MySQL error 1064, "You have an error in your SQL syntax", means the server could not parse your statement. Nothing was executed and no data was touched. The message reads like a shrug, but the fragment after near tells you exactly where the parser gave up. Usually the mistake is the word just before it.
How to read the message
The error is ER_PARSE_ERROR, number 1064, SQLSTATE 42000, with the format %s near '%s' at line %d (MySQL error reference). MariaDB uses the same number and format (MariaDB error codes). Here is the example from the MySQL manual:
mysql> CREATE TABLE interval (begin INT, end INT);
ERROR 1064 (42000): 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 'interval (begin INT, end INT)' at line 1
The quoted text is the rest of the statement, starting at the token the parser could not accept. Here it starts at interval, because INTERVAL is a reserved word and cannot be a table name unquoted (keywords and reserved words). begin and end are keywords too, but not reserved, so they are fine.
Three practical rules:
- Look at the token right before the quoted fragment. In our experience the actual mistake is there, or one token earlier: a missing comma, an extra comma before
FROM, an unclosed parenthesis. near ''with an empty fragment means the parser reached the end of the statement while still expecting more. Look for unclosed quotes or brackets, or a statement cut short by the client.- The line number counts from the start of the statement, not the file. In a 5,000-line dump, find the statement first, then the line.
The causes we see most often
- A reserved word used as a name. Columns called
rank,groups,system,leadorwindowworked on MySQL 5.7. They became reserved in 8.0 together withRECURSIVE,LATERAL,OVER,ROW_NUMBERand others (8.0 keywords). MySQL 8.4 addsQUALIFYandTABLESAMPLEas reserved words (8.4 keywords). Quote such names with backticks wherever they appear. Better, rename them while you can. - Double quotes around identifiers. Without the
ANSI_QUOTESSQL mode, MySQL treats"name"as a string, not a column (schema object names). Queries ported from PostgreSQL or generated by tools for another database then fail, or worse, return a constant. - Stored procedures and triggers without
DELIMITER. Themysqlclient splits input on;, so it sends the procedure body to the server in pieces, and the first piece fails with 1064 (defining stored programs).DELIMITERis a client command, not SQL (mysql client commands). GUI tools and drivers that send the whole statement in one call do not need it. IfDELIMITERitself reaches the server, the server returns 1064, because it is not SQL. - Syntax that the server version removed. See the next section. This is the cause that bites production systems.
- Strings built by hand. An unescaped apostrophe in a name like
O'Brienends the string literal early. The rest of the statement then fails to parse. If you see this in application logs, you have an SQL injection hole as well as a bug: use prepared statements with bound parameters. - Typos and copy-paste damage. Smart quotes from documents, non-breaking spaces, a trailing comma before
)inCREATE TABLE.
-- INTERVAL is reserved: quote it with backticks
CREATE TABLE `interval` (begin INT, end INT);
-- after a period it is always an identifier, no quotes needed
SELECT t.interval FROM schedule AS t;
-- double quotes are string literals unless ANSI_QUOTES is set
SELECT "id" FROM orders; -- returns the text 'id'
SET SESSION sql_mode = CONCAT(@@sql_mode, ',ANSI_QUOTES');
DELIMITER //
CREATE PROCEDURE archive_orders(IN days INT)
BEGIN
INSERT INTO orders_archive
SELECT * FROM orders WHERE created_at < NOW() - INTERVAL days DAY;
DELETE FROM orders WHERE created_at < NOW() - INTERVAL days DAY;
END //
DELIMITER ;
"It works on my machine." When the same statement succeeds in one place and fails with 1064 in another, compare SELECT VERSION(), @@sql_mode; on both. A different server version or a missing ANSI_QUOTES explains most of these cases in our experience.
Upgrades: when 1064 is a version problem
Each major version removes old syntax, and a removed statement is simply unknown to the parser. MySQL 8.0 removed the PASSWORD() function, so SET PASSWORD … = PASSWORD('…') no longer exists, and also removed changing account authentication through GRANT (What is new in MySQL 8.0). MySQL 8.4 removed the old replication statements: CHANGE MASTER TO, RESET MASTER, SHOW MASTER STATUS, START SLAVE, SHOW SLAVE STATUS and the rest of that family (What is new in MySQL 8.4).
-- removed in MySQL 8.0
SET PASSWORD FOR 'app'@'%' = PASSWORD('secret');
GRANT SELECT ON app.* TO 'app'@'%' IDENTIFIED BY 'secret';
-- use instead
ALTER USER 'app'@'%' IDENTIFIED BY 'secret';
CREATE USER 'app'@'%' IDENTIFIED BY 'secret';
GRANT SELECT ON app.* TO 'app'@'%';
-- removed in MySQL 8.4
SHOW MASTER STATUS; -- SHOW BINARY LOG STATUS
SHOW SLAVE STATUS; -- SHOW REPLICA STATUS
START SLAVE; -- START REPLICA
CHANGE MASTER TO ...; -- CHANGE REPLICATION SOURCE TO ...
RESET MASTER; -- RESET BINARY LOGS AND GTIDS
Application code is rarely the problem here. The usual victims are the things nobody reads before an upgrade: monitoring checks that run SHOW SLAVE STATUS, backup scripts that run SHOW MASTER STATUS to record a position, provisioning playbooks with CHANGE MASTER TO, and old user-management scripts. After an upgrade they fail quietly, and a replica lag alert that cannot parse its own query never fires. See our MySQL 8.0 to 8.4 upgrade guide for the full list of changes to plan for.
What changes on large systems
- Run the upgrade checker against the old server. MySQL Shell's
checkForServerUpgradeincludes areservedKeywordscheck that lists tables and columns whose names collide with new reserved words (upgrade checker utility). It cannot see queries in application code, cron jobs or BI tools, so you still need the next two steps. - Replay real traffic on a test replica. On a system with hundreds of services, no one can grep every query. In our experience the most reliable test is to set up a replica on the target version and replay a captured slow log or general log against it. Look for 1064 errors there before switching the primary.
- Restore dumps on the target version. A logical dump from an older server can contain syntax or names the new one rejects. On a multi-terabyte import, a 1064 on one table definition hours into the restore costs you a maintenance window. Test-restore on the target version first (see our mysqldump vs XtraBackup comparison).
- Watch the error counters. Performance Schema keeps per-error counters, including one for
ER_PARSE_ERROR, broken down globally and by user, host or account (error summary tables). A jump right after a deploy or upgrade tells you which account sends the broken statements, even when the application swallows the error. - Treat many 1064s from one account as a security signal. A steady stream of parse errors from a web application account often means someone is probing for SQL injection. It is worth checking which endpoint sends them.
# MySQL Shell: run against the OLD server before upgrading
mysqlsh -- util check-for-server-upgrade \
{ --user=admin --host=old-primary --port=3306 } \
--target-version=8.4.0 --output-format=JSON > upgrade-check.json
-- parse errors by account since restart (or since the table was truncated)
SELECT USER, HOST, SUM_ERROR_RAISED, FIRST_SEEN, LAST_SEEN
FROM performance_schema.events_errors_summary_by_account_by_error
WHERE ERROR_NUMBER = 1064 AND SUM_ERROR_RAISED > 0
ORDER BY SUM_ERROR_RAISED DESC;
Key takeaways
- Error 1064 means the statement did not parse. Nothing ran.
- The fragment after
nearstarts where the parser failed. Check the token just before it. - Quote reserved words with backticks. 8.0 reserved
RANK,GROUPS,SYSTEMand others, and 8.4 reservedQUALIFYandTABLESAMPLE. - Use
DELIMITERin themysqlclient for procedures and triggers. - 8.0 removed
PASSWORD(), and 8.4 removed theMASTER/SLAVEreplication statements. Fix scripts and monitoring before you upgrade. - On large systems, run the upgrade checker, replay traffic on a replica and watch the
ER_PARSE_ERRORcounters.