What the message looks like
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'order' at line 1Common causes
- A reserved word is used as a column or table name without backticks, for example
order,key,rankorgroups. - The code uses syntax only MySQL 8 knows (
RETURNING, functional indexes, window functions on old versions) but runs on MariaDB, or the other way around. ANSI_QUOTESis set insql_mode: double quotes then mean identifiers, not text.- String building produced broken SQL: a missing comma, an unescaped quote in a value or an empty pair of parentheses.
- The error comes from a migration or an import; the real context is in the line before.
Check
- Server version and sql_mode
mysql -e "SELECT VERSION(), @@sql_mode;" - Read the reported statement in the error log with context
grep -i -B2 -A2 'syntax' /var/log/mysql/error.log | tail -n 20 - Compare server and client version
mysql -e "SELECT VERSION()"; mysql --version
Fix
- Quote reserved words with backticks or rename them:
orderbecomesorder_ref. This is the most common cause. - Check the target version: what runs on MySQL 8 in staging can fail on MariaDB 10.11. Adjust the query or use the same engine.
- With
ANSI_QUOTES, write text values with single quotes and identifiers with backticks. - For dynamically built SQL, log the final string before sending it. The missing comma becomes obvious.
- After the fix run the migration against a copy first, not on production.
Typical scenario
After moving from MySQL 5.7 to 8.0, an application suddenly runs into ERROR 1064 (42000): You have an error in your SQL syntax ... near 'rank int'. The column name rank became a reserved word in MySQL 8 and has to be wrapped in backticks. In the message, read the part after near: that is where the parser gave up, and the actual mistake is usually right before it.
FAQ
Why does it work on staging but not in production?
Different versions or sql_mode. Compare SELECT VERSION(), @@sql_mode on both systems.
Does an upgrade help?
Only if the query is valid on the new version. An upgrade does not add missing backticks.
How do I write reserved words as column names?
Wrap the name in backticks, such as `rank` or `groups`. That applies in every statement that uses the name. Alternatively rename the column. The list of reserved words differs by version and between MySQL and MariaDB.
How do I read the part after near correctly?
MySQL shows the text from the point where the parser stopped understanding. The problem often lies just before: a missing comma, an extra bracket, an unescaped quote. If near shows empty text, something is missing at the end, such as a value.
Why does 1064 occur with statements from code?
If the application builds SQL from text, a quote inside a value breaks the syntax. Prepared statements with placeholders avoid that and also protect against SQL injection. Log the fully assembled statement to see the broken spot.