16

MySQL only gives an unhelpful error message when it encounters a grammar or syntax error:

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 .......

Is there any way to let MySQL to explain syntax error (e.g. expecting closing parenthesis, illegal expression, etc) in details?

4
  • 1
    It's actually pretty helpful, but I see your point. Commented Dec 6, 2012 at 23:11
  • 1
    A syntax error occurs at the spot when the first unexpected "token" is found, so the actual error should be found a few characters earlier. Reading the manual thoroughly is your only way out otherwise :) Commented Dec 6, 2012 at 23:12
  • thank you.. sometimes I make a mistake in function call such as ifnull(sum(margin, 0)) rather than ifnull(sum(margin), 0), mysql tells me that it is a 'syntax error', i wish it could be more helpful and tell me that sum takes only one parameter. Commented Dec 6, 2012 at 23:17
  • 1
    I'm sure if they had code to give detailed errors it would be enabled by default. Commented Dec 6, 2012 at 23:45

1 Answer 1

5
+50

The answer is - no. All server errors messages and their codes are listed in the documentation.

Server Error Codes and Messages.

From the documentation - For error checking, use error codes, not error messages. Error messages do not change often, but it is possible.

About the syntax errors: if there are no more specific error codes, then you get Error: 1149 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax...


As a work around: You can view all syntax errors in dbForge Studio for MySQL. Create new SQL document and write some code, or just open SQL-file, automatic SQL syntax check will highlight errors in the code.

Automatic SQL syntax check feature.

This feature is available in Professional and Enterprise editions, but you can try it on trial version.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.