Error 1064 is the parser telling you it could not understand the statement. Nothing was executed. The useful part is the end of the message, which shows where parsing stopped.
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
'order (id, total) VALUES (1, 9.99)' at line 1
MariaDB words it the same way, with "MariaDB server version". The text after near starts at the first token the parser could not accept. The mistake is usually at the very start of that quoted snippet or just before it.
How to read the message
- If the snippet starts with a keyword like
order,grouporkey, you probably used a reserved word as a name. - If the snippet is empty (
near '' at line 1), the statement ended too early: a missing value, a danglingWHERE, or an unclosed quote or parenthesis. - The line number counts lines within the statement, not within your source file.
- If the snippet shows something odd like
\',?or:name, the placeholder was never replaced by your driver.
Cause 1: reserved words as table or column names
order, group, key, desc, rank, index, release and many others are reserved. Wrap identifiers in backticks:
INSERT INTO `order` (`id`, `total`) VALUES (1, 9.99);
Better, rename the table to orders. The list differs by version (RANK and GROUPS became reserved in MySQL 8.0, which breaks some old schemas on upgrade). Check the keywords page in the manual for your version.
Backticks are MySQL-specific. Double quotes work for identifiers only when sql_mode includes ANSI_QUOTES; otherwise they delimit strings.
Cause 2: quoting and escaping errors
An unescaped apostrophe in a string ends it early:
-- Breaks
INSERT INTO notes (body) VALUES ('It's done');
-- Works
INSERT INTO notes (body) VALUES ('It''s done');
Never build SQL by concatenating user input. Use prepared statements with bound parameters, which fix both the syntax errors and SQL injection:
$stmt = $pdo->prepare('INSERT INTO notes (body) VALUES (:body)');
$stmt->execute([':body' => $text]);
If a query shows a literal $var or {$name} in the error snippet, string interpolation failed before the query was sent.
Cause 3: punctuation and structure
- A trailing comma:
SELECT id, name, FROM usersor the last column inCREATE TABLE. - A missing comma between columns or values.
- Unbalanced parentheses in a long
WHERE ... AND (... OR ...). LIMITwith a bound parameter in emulated-prepare PDO mode, where the number arrives quoted as'10'. Bind withPDO::PARAM_INTor turn offPDO::ATTR_EMULATE_PREPARES.- A missing
DELIMITERchange when creating stored procedures through themysqlclient, so it splits the statement at the first semicolon. - Statements pasted from PostgreSQL or SQL Server:
RETURNING,TOP 10,::intcasts,ILIKE,[brackets]andSERIALare not valid MySQL.
Cause 4: version and engine differences
Syntax your local server accepts may not exist on the production one.
WITHcommon table expressions and window functions (OVER) need MySQL 8.0 or newer (CTEs also need MariaDB 10.2.1+, window functions 10.2.0+). On MySQL 5.7 they raise 1064.CREATE TABLE ... GENERATED ALWAYS ASneeds 5.7+.ALTER TABLE ... ADD COLUMN IF NOT EXISTSworks in MariaDB but not in MySQL.JSON_TABLE,INSERT ... AS aliasandCHECKconstraint enforcement vary by version.- Collations such as
utf8mb4_0900_ai_ciexist in MySQL 8 but not MariaDB; that normally gives a different error, but dumps moved between the two often fail near theCOLLATEclause.
Run SELECT VERSION(); on the server that rejected the query, not the one on your laptop.
A debugging routine
- Copy the exact failing SQL from the log or from
SHOW PROCESSLIST, with parameters filled in. - Paste it into the
mysqlclient against the same server. - Cut the statement down until it works, then add parts back one at a time. The last thing you added is the culprit.
- For huge dump imports, the line number from the
mysqlclient points at the statement. Usesed -n '1200,1210p' dump.sqlto look at it. - If a migration tool generated the SQL, turn on its query log, because you are debugging what was sent, not what you wrote.
Dumps from mysqldump can fail on import with 1064 if they were written by a newer server version with options such as SET @@SESSION.SQL_LOG_BIN or GTID statements an older server does not know. Re-dump with --set-gtid-purged=OFF where applicable, or remove those lines.
Next steps
- If the statement parses but refers to a missing table, read MySQL error 1146.
- Garbled text in inserts? See MySQL error 1366.
- Validate JSON you store in columns with the JSON Validator and the JSON Formatter.
- Fix framework crashes with Fix 500 Internal Server Error.
FAQ
Does error 1064 mean the database is broken?
No. It is a client-side mistake in the SQL text. The server and your data are unaffected.
Why does the same query work on my laptop?
Your laptop probably runs a different MySQL or MariaDB version, with different keywords and features. Compare SELECT VERSION(); on both.
Why does the error show near an empty string?
The parser reached the end of the statement while still expecting more, so look for a missing value, an unclosed quote, or a dangling clause.
Are backticks safe to use everywhere?
In MySQL and MariaDB, yes. They are not portable to PostgreSQL or SQL Server, so use an ORM or double-quote mode if you need portability.
Get notified when this fix updates
Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.
This page is general information written by our editorial team and updated when documentation changes. Servers and providers differ, so test changes safely first. See our editorial policy and disclaimer.