How can I check the SQL syntax in a .sql file?
There are a few free/try-ware products out there that will allow you to connect to a MySQL database or just paste in the script to validate it. Google is your friend here. Mimer will check ANSI-Standard syntax validation but probably not handle any MySQL specifics.
There are a couple of possiblities. If you are using InnoDB tables that support transactions, you can simply execute a start transaction;
at the beginning of your .sql file and a rollback;
at the end. MySQL will output any syntax errors.
If you are testiing UPDATE
or DELETE
statements, you could add LIMIT 0
to the end to prevent these queries from making any database changes, and still have MySQL check the syntax.
The basic lexer seems to be implemented in sql/sql_lex.cc. You could use/salvage this to build your own test parser. But this would only check for syntax but not any runtime errors.
You could paste it into a query browser like the MySQL Query Browser (part of the GUI Tools package) and visually inspect how the keywords and string literals are colored to more easily see if you've made any syntax errors.