Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Databases and Redis

The server could not parse an SQL statement (error 1064)

ErrorERROR 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 1

Short 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.

  • Applies to MariaDB 11.4 LTS, MySQL 8.4 LTS, mariadb client 11.4
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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();
  2. 2Match what you see, then jump to its fix

    1. 1near 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. 2near points at a string value or a name in double quotesDouble quotes or backticks are used for the wrong thingFix
    3. 3near '' at line 1, or a stored procedure fails on its first semicolonThe statement ends too early, so near is emptyFix

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 1
  • ERROR 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

Did this fix it?

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

Did this fix it?

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 FROM

2Fix

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\G

Confirmed by mariadb.com

Did this fix it?

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:

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.