MySQL error 1064
ERROR 1064 (42000): You have an error in your SQL syntax
The parser hit something it couldn’t make sense of. The text after “near” is where it gave up; the mistake is usually right before it. “near ''” means the statement ended too early.
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 'order (id int PRIMARY KEY)' at line 1
Tested on MySQL 8.4.11 and MariaDB 11.4.13 · Updated 9 October 2026
What it means
MySQL and MariaDB couldn’t parse the statement, so nothing ran. The useful part is at the end:
… for the right syntax to use near 'FROM customers' at line 1
near '…'quotes your statement from the first piece the parser couldn’t use, to the end (cut short if long). The mistake is usually right before that text: inSELECT id, name email, FROM customersthe parser stops atFROM, but the problem is the comma before it.near ''(nothing in the quotes) means the statement ended while the parser still expected more: a danglingWHERE,ORDER BYorOFFSET, or a body cut off at a semicolon.at line Ncounts lines from the start of the statement, not of your file.
MariaDB prints the same message with “MariaDB server version” in place of “MySQL server version”.
Common causes
- A reserved word used as a name:
order,group,key,rank. MySQL 8 added window-function words such asRANK,LEADandLAGto the reserved list, so old schemas can break on upgrade. - A stray or missing comma, or a trailing comma before
)orFROM. - An unescaped quote inside a string:
'O'Brien'ends the string atO. - SQL from another database: PostgreSQL’s
::text,ILIKEor"double-quoted"names, SQL Server’sTOP 5. - An unfinished statement:
WHERE,ORDER BYorLIMIT 10 OFFSETwith nothing after them. - A stored procedure or trigger without
DELIMITER. Themysqlclient splits on;, so it sends the body in pieces. - A newer feature on an older server, or a MariaDB-only one on MySQL (or the other way round):
INSERT … RETURNINGworks on MariaDB but not MySQL.
How to fix it
Quote names with backticks
CREATE TABLE `order` (id int PRIMARY KEY);
SELECT `rank` FROM players;
Better still, rename columns that collide with keywords. The keyword list marks reserved words with (R).
Escape quotes inside strings
Double the quote, or use a parameter from your driver instead of building SQL by hand:
UPDATE customers SET name = 'O''Brien' WHERE id = 1;
Translate syntax from other databases
| Instead of | In MySQL / MariaDB |
|---|---|
id::text | CAST(id AS CHAR) |
name ILIKE 'a%' | name LIKE 'a%' (case-insensitive with _ci collations) |
"customers" | `customers` |
SELECT TOP 5 * | SELECT * … LIMIT 5 |
INSERT … RETURNING id (MySQL) | LAST_INSERT_ID() after the insert |
Set a delimiter for procedures and triggers
DELIMITER //
CREATE PROCEDURE seo_p()
BEGIN
SELECT 1;
SELECT 2;
END//
DELIMITER ;
DELIMITER is a command of the mysql client, not SQL. GUI clients and drivers that send the whole
statement at once don’t need it.
Look at the text before “near”
Format the statement one clause per line and run it again: at line N then points at the clause, and
the quoted text shows where in it the parser stopped.
Reproduce it
On MySQL 8.4.11:
CREATE TABLE order (id int PRIMARY KEY);
SELECT id, name email, FROM customers;
SELECT rank FROM customers;
SELECT id::text FROM customers;
SELECT * FROM customers WHERE name ILIKE 'a%';
SELECT TOP 5 * FROM customers;
CREATE TABLE seo_t (id int, name varchar(20),);
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 'order (id int PRIMARY KEY)' at line 1
… near 'FROM customers' at line 1
… near 'FROM customers' at line 1
… near '::text FROM customers' at line 1
… near 'ILIKE 'a%'' at line 1
… near '5 * FROM customers' at line 1
… near ')' at line 1
An unfinished statement over six lines, ending in ORDER BY;:
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 6
'O'Brien' swallowed the rest of the script into one broken statement:
… near 'Brien' WHERE id = 1;
SELECT id FROM customers LIMIT 10 OFFSET;
CREATE TABLE `ord' at line 1
A procedure body sent without DELIMITER failed twice, once for each piece:
… near '' at line 3
… near 'END' at line 1
MariaDB 11.4.13 gave the same results except two: SELECT rank FROM customers failed with
Unknown column 'rank' (error 1054) because RANK isn’t reserved there, and
INSERT … RETURNING id ran and returned the new id.
In Inlet
Inlet shows a syntax error at the position the server reports, so the editor marks where the parser stopped, and adds a hint for common mistakes. The formatter puts one clause per line, and with your own Anthropic API key Ask Claude (⌘L) can fix the failed statement.