ERROR 1064 (42000): You Have an Error in Your SQL Syntax
Error 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 '...' at line NDescription
MySQL error 1064 means the parser could not understand your SQL statement. The near '...' portion of the message shows where MySQL gave up trying to parse. Everything before that point was accepted; the error starts at (or just before) the quoted text.
This is the single most common MySQL error. It covers everything from a missing comma to using a reserved word as a column name.
Causes
- Typos in SQL keywords.
SELCET,UDPATE,FORMinstead ofSELECT,UPDATE,FROM. - Missing or extra punctuation. Unmatched parentheses, missing commas between column definitions, trailing commas before a closing parenthesis.
- Using a reserved word as an identifier. Column or table names like
order,group,key,status,rank,indexconflict with MySQL keywords. - Version mismatch. Syntax valid in MySQL 8.0 (like
LATERAL, window functions, orWITHCTEs) fails on MySQL 5.7. - Importing a dump from a different engine. A PostgreSQL or SQL Server dump contains syntax MySQL does not recognize.
- Wrong string quoting. Using double quotes for strings instead of single quotes (unless
ANSI_QUOTESSQL mode is enabled). - Invisible characters. Copy-pasting SQL from a web page or PDF can introduce non-breaking spaces or zero-width characters that look fine but break parsing.
Solutions
-
Read the error message carefully. MySQL tells you exactly where parsing failed. The text after
nearis the first thing it couldn't parse:-- Error: ... near 'FROM users WHERE id = 1' at line 1 -- The problem is right before FROM â likely a missing column name or comma -
Escape reserved words with backticks:
-- Fails: order is a reserved word SELECT * FROM order WHERE id = 1; -- Works SELECT * FROM `order` WHERE id = 1; -
Check for missing commas and parentheses:
-- Fails: missing comma between columns CREATE TABLE users ( id INT PRIMARY KEY name VARCHAR(100) -- missing comma on previous line ); -- Works CREATE TABLE users ( id INT PRIMARY KEY, name VARCHAR(100) ); -
Remove trailing commas:
-- Fails: trailing comma before closing parenthesis INSERT INTO users (name, email,) VALUES ('Alice', 'alice@example.com'); -- Works INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com'); -
Check your MySQL version:
SELECT VERSION();If you're using MySQL 5.7 and the query uses 8.0+ syntax (CTEs, window functions,
GROUPING), rewrite it or upgrade. -
Strip invisible characters. Re-type the query manually in your SQL client rather than pasting from a browser or document.
Common scenarios
WordPress and CMS database imports: Importing a .sql dump into a different MySQL version often triggers 1064 on statements like CREATE TABLE that use newer column types or options. Check the MySQL version at the source and target.
ORM-generated queries: When an ORM builds SQL that references a reserved word as a column name without backticks, you get 1064. Most ORMs have a setting to force-quote identifiers.
Stored procedures and triggers: Syntax errors inside BEGIN...END blocks are harder to spot. Simplify the procedure to the minimum and add statements back one at a time.
Bytebase's SQL Review checks SQL syntax and common mistakes before changes reach your database. You can configure rules for MySQL naming conventions and reserved word usage.