Menu

MySQL Error 1064: Fix SQL Syntax Errors

Diagnose MySQL Error 1064 by checking the reported token, missing punctuation, reserved identifiers, quoting, and server-version syntax.

Posted on
On this page

MySQL Error 1064 (SQLSTATE 42000, ER_PARSE_ERROR) means the server could not parse the statement as valid SQL. The error message usually includes a fragment after near and a line number. The fragment marks where parsing failed; the missing comma, quote, or parenthesis may be earlier in the statement. See the MySQL 8.4 error reference.

Capture the error and server version

Note the server version before testing syntax that may vary across releases:

SELECT VERSION();

After the failing statement, run SHOW ERRORS before another SQL statement replaces the diagnostics:

SHOW ERRORS;

Check the token before the reported location

Missing comma or closing delimiter

This table definition is missing a comma after the primary-key column:

CREATE TABLE orders (
  order_id INT PRIMARY KEY
  customer_id INT NOT NULL,
  total DECIMAL(10, 2) NOT NULL
);

Add the comma between the column definitions:

CREATE TABLE orders (
  order_id INT PRIMARY KEY,
  customer_id INT NOT NULL,
  total DECIMAL(10, 2) NOT NULL
);

Also check paired quotes and parentheses near the error position.

Reserved word used as an identifier

Reserved words need special handling when used as table or column names. INTERVAL is reserved, so this statement fails:

CREATE TABLE interval (begin INT);

Prefer a descriptive nonreserved name. If a legacy schema requires the identifier, quote it with backticks:

CREATE TABLE `interval` (`begin` INT);

See MySQL’s current reserved-word list and identifier quoting rules.

Check dialect and statement shape

MySQL, MariaDB, SQL Server, PostgreSQL, and SQLite do not accept identical syntax. Confirm that the statement matches both MySQL and the server version reported by SELECT VERSION().

For an INSERT, a value-count mismatch has its own error: Error 1136. Compare the target column list with every VALUES tuple or SELECT expression using the MySQL Error 1136 guide. For standard insert forms, see the MySQL INSERT tutorial.

If the error remains, reduce the statement to the smallest fragment that still fails, then add clauses and expressions back one at a time. This makes it easier to find the first syntax element that MySQL cannot parse.