- Error number
- 1064
- SQLSTATE
42000- Symbol
ER_PARSE_ERROR- Product
- MySQL Server
- Versions
- All MySQL versions (checked on MySQL 8.0.46); which words are reserved depends on the version
- Category
- Syntax & Names
- Last reviewed
- 24 October 2026
On this page
What it means
Error 1064 means MySQL could not parse the statement: something in it is not valid MySQL syntax, and the quoted text shows where parsing stopped.
MySQL reads a statement from left to right and stops at the first token that cannot continue a valid statement. The text after near starts at that token and runs to the end of the statement (shortened if long), and at line n counts lines inside the statement. So in SELECT id, name, FROM customers the message says near 'FROM customers': the mistake is the comma just before it, which promised another column. The real error is usually at the start of the quoted text or immediately before it.
An empty near '' means MySQL reached the end of the statement while still expecting more: an unfinished WHERE, a missing closing bracket, or a statement cut short by the application. Reserved words are another frequent cause: since MySQL 8.0.2 words such as rank and groups are reserved, so tables and columns with those names must be quoted with backticks. Syntax from other databases (TOP, square-bracket names) also raises 1064. Errors about names that parse correctly but do not exist are different errors, such as 1054 and 1146.
Common causes
- A typo in a keyword or a missing keyword:
FORMfor FROM,ORDER namewithout BY, a missing comma between SET assignments. - A stray or missing comma, typically a trailing comma before FROM or before the closing bracket of CREATE TABLE.
- A reserved word used as an unquoted identifier, for example a column called
rank,orderorgroups. - Unbalanced quotes or brackets, often from a value such as O'Brien glued into the SQL string by application code instead of being passed as a parameter.
- Syntax from another database: SQL Server's
SELECT TOP 5or[column], or a feature newer than the server version you are running.
Diagnose it
Read-only These statements only read metadata (information_schema, performance_schema and SHOW statements) or your own data. They do not change data, privileges or configuration, so they are safe to run first.
Which server version are you writing for?
The message tells you to check the manual for your version because syntax and reserved words change between releases. A statement copied from newer documentation may not parse on an older server.
SELECT VERSION() AS server_version; The exact version. Read the statement syntax in the reference manual for that release series.
Is the word next to the error reserved?
SELECT word, reserved
FROM information_schema.keywords
WHERE word IN ('RANK', 'GROUPS', 'ORDER', 'STATUS'); reserved = 1 means the word must be quoted with backticks when it is used as a table or column name. Words with reserved = 0 are keywords that can still be used unquoted.
How to fix it
Each fix is labelled with what it changes. Try read-only checks and the least invasive fix first, and test changes outside production.
Read the error at the start of the "near" text
Read-onlyFind the quoted text in your statement and look at the token where it starts and the one just before it. Use at line n to find the line inside a multi-line statement; when the mysql client runs a script it also prints at line n after the error number, which is the line in the file where that statement starts.
Fix the keyword, comma or bracket
Client or network sideMost 1064 errors are one character or one word. Check the clause order too: SELECT, FROM, JOIN, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT.
SELECT id, name
FROM customers
WHERE city = 'Leeds'
ORDER BY name
LIMIT 5;
Quote reserved words with backticks, or rename them
Client or network sideBackticks make any word usable as an identifier. For new tables, a name that is not a keyword (for example player_rank) avoids the problem in every query and every tool.
CREATE TABLE scores (
id INT PRIMARY KEY,
player VARCHAR(50),
`rank` INT
);
SELECT player, `rank` FROM scores ORDER BY `rank`;
Pass values as parameters instead of building SQL strings
Client or network sideA name such as O'Brien contains a quote that ends the string early when it is pasted into SQL. Prepared statements with bound parameters keep values out of the SQL text, which removes this whole class of syntax errors and also prevents SQL injection. In hand-written SQL, double the quote: 'O''Brien'.
// PHP PDO
$stmt = $pdo->prepare('INSERT INTO customers (id, name, city) VALUES (?, ?, ?)');
$stmt->execute([2, "O'Brien", 'Leeds']);
Examples
FORM instead of FROM
The near text is 'customers', not 'FORM customers': FORM is not a keyword, so MySQL reads it as an alias for name (name AS FORM) and only fails at the next word.
CREATE TABLE customers (id INT PRIMARY KEY, name VARCHAR(100), city VARCHAR(50));
SELECT id, name FORM customers;
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 'customers' at line 1
Reproduced on MySQL 8.0.46, 24 October 2026.
A reserved word as a column name
CREATE TABLE scores (id INT PRIMARY KEY, player VARCHAR(50), rank 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 'rank INT)' at line 1
Reproduced on MySQL 8.0.46, 24 October 2026.
ORDER without BY in a multi-line query
CREATE TABLE customers (id INT PRIMARY KEY, name VARCHAR(100), city VARCHAR(50));
SELECT id, name
FROM customers
WHERE city = 'Leeds'
ORDER name;
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 'name' at line 4
Reproduced on MySQL 8.0.46, 24 October 2026.
SQL Server TOP syntax on MySQL
CREATE TABLE customers (id INT PRIMARY KEY, name VARCHAR(100), city VARCHAR(50));
SELECT TOP 5 * FROM customers; -- MySQL uses LIMIT 5
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 '5 * FROM customers' at line 1
Reproduced on MySQL 8.0.46, 24 October 2026.
How to prevent it
Write SQL in an editor that highlights MySQL syntax, format long statements one clause per line so at line n points somewhere useful, and avoid reserved words as table and column names. When you copy SQL from another database or from documentation, check it against the manual for your server version.
In application code, never assemble SQL by concatenating values; use prepared statements with bound parameters. Log the full statement text (without secrets) when a 1064 occurs, because the bug is usually in the generated SQL, not in the code that sent it.
Common questions
How do I find where a MySQL 1064 syntax error is?
Look at the text after near: it starts at the first token MySQL could not accept, so the mistake is at the start of that text or just before it. at line n gives the line within the statement. An empty near '' means the statement ended too early.
Why does a column called rank or groups cause error 1064?
They became reserved words in MySQL 8.0.2, together with other window function names. Quote them with backticks (`rank`) everywhere they are used, or rename the column. You can check any word in information_schema.keywords.
Why is the line number in the error different from the line in my file?
The at line n at the end of the message counts lines inside the failing statement. When the mysql client runs a script, it adds its own at line n right after the error number, which is the line in the file where that statement starts.
Why does a query that works in SQL Server give 1064 in MySQL?
Each database has its own dialect. SELECT TOP n, square-bracket identifiers and some date functions are SQL Server syntax; in MySQL use LIMIT n, backticks and the MySQL function names.
Learn more on CodeWithSQL
Official documentation
- Keywords and reserved words
- Schema object names (quoting identifiers)
- String literals (quotes inside strings)
- MySQL 8.0 server error message reference
Last technically reviewed 24 October 2026; examples and diagnostics run on MySQL 8.0.46. Message templates checked against the server's error catalogue (perror) for that version.