Skip to content
MySQL

MySQL Error 1064

You have an error in your SQL syntax

Applies to: All MySQL versions (checked on MySQL 8.0.46); which words are reserved depends on the version
Last technically reviewed 24 October 2026 on MySQL 8.0.46
The full message
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 'FROM customers' at line 1
Other forms of this message
The statement ended too early (nothing left to show)
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 '' at line 1
mysql client reading a script file (script line, then line inside the statement)
ERROR 1064 (42000) at line 3: 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 'FROM customers' at line 1
PHP PDO
SQLSTATE[42000]: Syntax error or access violation: 1064 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 'FROM customers' at line 1
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
Last reviewed
24 October 2026

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: FORM for FROM, ORDER name without 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, order or groups.
  • 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 5 or [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;
What to look for

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');
What to look for

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-only

Find 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 side

Most 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 side

Backticks 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 side

A 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;
Result
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);
Result
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;
Result
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
Result
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

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.

Still stuck on a MySQL error?

Browse the full MySQL error library, or get hands-on help from an experienced SQL professional.