The server could not parse an SQL statement (error 1064)
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 (id, total) VALUES (1, 5)' at line 1Short answer
Error 1064 means the parser stopped at a place where the statement made no sense to it. Read the text after the word near: the mistake is there or just before it. An empty near means the statement ended too early. Usual causes are a reserved word used as a name, wrong quotes, or a client cutting the statement at a semicolon.
Fix it fast
1Find out which cause you have
Find your server version, then take the text between the quotes after near and look at the last word in it. The parser gave up there.
SELECT VERSION();2Match what you see, then jump to its fix
- 1
near points at a name such as order, group, key, rank, system or a new keywordA reserved word is used as a table or column nameFix - 2
near points at a string value or a name in double quotesDouble quotes or backticks are used for the wrong thingFix - 3
near '' at line 1, or a stored procedure fails on its first semicolonThe statement ends too early, so near is emptyFix
- 1
What does the error look 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 (id, total) VALUES (1, 5)' at line 1ERROR 1064 (42000): You have an error in your SQL syntax; ... near '' at line 1
Cause 1 of 3
A reserved word is used as a table or column name
1Check
Compare the word in the near text with the list of reserved words. A name that worked on an older server can become reserved after an upgrade.
-- the failing form
INSERT INTO order (id, total) VALUES (1, 5);2Fix
Wrap the identifier in backticks everywhere it is used, or rename it. Quoting every keyword-like name protects against later versions.
INSERT INTO `order` (id, total) VALUES (1, 5);
ALTER TABLE t1 ADD `system` VARCHAR(64);3Verify
The statement now runs.
SELECT COUNT(*) FROM `order`;Confirmed by mariadb.com
Cause 2 of 3
Double quotes or backticks are used for the wrong thing
1Check
By default double quotes are string quotes; with the ANSI_QUOTES mode they quote identifiers instead. A script written for one mode breaks on the other.
SELECT @@sql_mode;2Fix
Use single quotes for values and backticks for identifiers. Both work in every mode.
SELECT `name` FROM `customers` WHERE city = 'Leeds';3Verify
The statement runs under the current sql_mode.
SELECT @@sql_mode;Confirmed by mariadb.com
Cause 3 of 3
The statement ends too early, so near is empty
1Check
An empty near text means the statement stopped before it was complete: FROM with no table, an unclosed bracket, or a procedure body cut at the first ; because the client treats ; as the end.
SELECT id, total FROM2Fix
Complete the statement. For stored programs, change the client delimiter around the body.
DELIMITER //
CREATE PROCEDURE p()
BEGIN
SELECT 1;
SELECT 2;
END//
DELIMITER ;3Verify
The procedure is created.
SHOW CREATE PROCEDURE p\GConfirmed by mariadb.com
How do I stop it coming back?
- Quote identifiers with backticks in generated SQL and migrations.
- Run the same server version in development, CI and production.
- Keep SQL in files and run them with the client instead of pasting through chat tools that change quotes.
- Re-run the whole migration set on a copy before upgrading the server.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- ShopGoAn e-commerce aggregator with a Python scraping engine behind its catalog, past 10K Google Play downloads.
Related fixes
Databases
ALTER TABLE ADD COLUMN with AFTER gives a syntax error
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 'AFTER'
The parenthesized form ADD COLUMN (a INT, b INT) cannot take FIRST or AFTER.
2 causes, each with a fixDatabases
Installing the Airflow MySQL provider fails on pkg-config or mysqlclient
Building the mysqlclient wheel fails during the install
The Airflow MySQL provider depends on mysqlclient, which pip compiles against the MySQL C client library.
2 causes, each with a fixDatabases
A query on Aurora MySQL dies with 'table /rdsdbdata/tmp/#sql... is full'
ERROR 1114 (HY000): The table '/rdsdbdata/tmp/#sqlfd_1586_2' is full
In Aurora MySQL 3, internal temporary tables share one pool, and when that pool and the memory-mapped overflow file are used up, a reader instance ends the query with error 1114.
3 causes, each with a fixDatabases
Azure Database for MySQL refuses a connection that does not use SSL
ERROR 3159 (HY000): Connections using insecure transport are prohibited while --require_secure_transport=ON.
Azure Database for MySQL Flexible Server requires encrypted connections by default (require_secure_transport = ON, TLS 1.2).
4 causes, each with a fixDatabases
Compiling a C or C++ program that includes mysql.h fails
undefined reference to `mysql_init'
The compiler only finds mysql.h when the MySQL client development files are installed and their folder is on the include path.
3 causes, each with a fixDatabases
DBeaver fails to resolve Maven dependencies when downloading a database driver
A driver library does not download automatically
DBeaver downloads driver jars from a Maven repository.
3 causes, each with a fix