Understanding SQL code errors

When MySQL encounters errors with your script or actions in MySQL Workbench, it puts a message for you in the Output panel. 

By default, the Output panel is at the bottom of the MySQL Workbench application. You can resize it by clicking on the divider between the script file area and the Output panel. 

I changed the script that we ran in the previous section so that there is a space in the schema name that isn't allowed unless you have backticks around it (because it is a MySQL keyword). MySQL will show an error in the Output panel when I run it, as shown in the following screenshot:

The Output window will show you the time, the action, the message, and the duration/fetch:

  • The Time column tells you the time of the day that you ran the query. 
  • The Action column shows you what query was executed. 
  • The Message column shows you whether the action was successful and also tells you the number of rows that a query returned, if any.
  • The Duration/Fetch column shows you how long the action took to complete.

To see the entire error message, right-click it, and select Copy Response, as shown in the following screenshot:

You can then paste this response information into a query window or a text editor of your choosing. The important thing is to see the entire message. The whole message is Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'schema' at line 1

The error message will show any information it can tell you about the error you and the line in which you have the problem. Sometimes the errors are cryptic, but you can usually tell where the problem is on the line because MySQL Workbench will put red squiggly lines under the problem area. In the preceding screenshot with the script in it, you can see that MySQL Workbench has a red squiggly line under the schema. We know that we can't have spaces in a schema name (without using backticks), so MySQL Workbench is warning us that this won't work, and sure enough, when we run the script, it gives us an error. You will either need to make your schema one word in the script or put your schema in backticks—for example, `your schema`. I highly advise against using spaces in a database (schema) name. 

The Output panel will show you any errors that you have, and they will accumulate there over time. If you want to clear out the errors, then you can right-click in the Output panel and select Clear, as shown in the following screenshot. This will clear all your messages from the Output window, so only use this if you want to clear everything out:

 

The Output window is a useful panel. As described in Chapter 2, Installing and Using MySQL Workbench, the Output window also shows you successful queries, and it's where you can go to look for success and failure messages. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.253.62