How to fix ERROR 1064: Syntax error near in MySQL
MySQL error 1064 indicates a syntax error in your SQL query. This happens when MySQL encounters mistyped commands, reserved words used as identifiers, incorrect punctuation, or deprecated syntax that it cannot parse.
Quick fix
Fixes 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 '<problem area>' at line X- Read the error message carefully
- Check for typos in SQL keywords
- Wrap reserved words in backticks
- Verify parentheses, quotes, and punctuation
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 '<problem area>' at line XERROR 1064: Syntax error near
What this error means
MySQL error 1064 (ER_PARSE_ERROR) is thrown when the MySQL parser encounters an SQL statement it cannot understand. This is not a runtime error—it occurs at the parsing stage before any query execution. The error means your SQL syntax violates MySQL rules or contains commands MySQL does not recognize. Common culprits include typos in keywords, reserved words used without backticks, missing or extra punctuation, and deprecated commands from older MySQL versions.
Typical symptoms
- SQL queries fail immediately with "You have an error in your SQL syntax"
- Error message includes the approximate location of the syntax error ("near...")
- Same query works on different MySQL version but fails on yours
- Database operations fail in your application code when executing prepared statements
- Stored procedures or triggers cannot be created due to syntax errors
Common causes
- Typos or misspelled SQL keywords (e.g., SLECT instead of SELECT, INSRT instead of INSERT)
- Using MySQL reserved words as table or column names without backticks (e.g., `select` must be wrapped)
- Mismatched or missing parentheses, brackets, or quotes in the query
- Obsolete or deprecated syntax (e.g., TYPE=InnoDB instead of ENGINE=InnoDB in older MySQL versions)
- Missing required clauses or values in INSERT, UPDATE, or CREATE statements
- Incorrect use of quotes—using double or single quotes for identifiers instead of backticks
- Version-specific syntax differences when migrating between MySQL 5.7 and 8.0
- Extra or missing commas in column lists or function arguments
How to fix "ERROR 1064: Syntax error near"
MySQL provides helpful error output that includes the location of the syntax error. The message format is:
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 '<problem area>' at line XThe text shown after "near" pinpoints the problematic area. Focus your search on that location and surrounding code.
Review your query for common misspellings:
-- Wrong (typo)
SLECT * FROM users;
-- Correct
SELECT * FROM users;Also verify keywords like INSERT, UPDATE, DELETE, WHERE, FROM, JOIN, GROUP BY, ORDER BY are spelled correctly.
If you use MySQL reserved words (SELECT, FROM, WHERE, ORDER, GROUP, etc.) as table or column names, wrap them in backticks:
-- Wrong (reserved word without backticks)
SELECT order FROM products;
-- Correct
SELECT `order` FROM products;Do NOT use single (') or double (") quotes for identifiers—those are for string literals only.
Check that:
- All opening parentheses have matching closing ones
- String values are enclosed in single quotes (e.g., 'John')
- Column lists have commas between items
- All semicolons are at the end of complete statements
-- Wrong (missing closing parenthesis)
SELECT * FROM users WHERE id IN (1, 2, 3;
-- Correct
SELECT * FROM users WHERE id IN (1, 2, 3);
-- Wrong (unquoted string)
SELECT * FROM users WHERE name = John;
-- Correct
SELECT * FROM users WHERE name = 'John';If migrating from MySQL 5.0 or earlier, update deprecated commands:
-- Old (deprecated in MySQL 4.1, removed in 5.1)
CREATE TABLE users (id INT) TYPE=InnoDB;
-- New
CREATE TABLE users (id INT) ENGINE=InnoDB;Check the MySQL Reference Manual for your version to identify deprecated features.
Tools like MySQL Workbench (official tool from MySQL) provide real-time syntax checking and highlighting. They catch 1064 errors before you execute:
- MySQL Workbench: Free, official, includes SQL editor with error highlighting
- SQL Fiddle: Web-based SQL testing tool
- Your IDE: Many code editors have SQL extensions with syntax validation
Copy your query into one of these tools to get instant feedback.
Syntax varies between MySQL versions. Verify your MySQL version:
SELECT VERSION();Then check the MySQL Reference Manual for your version. Features added in MySQL 8.0 will not work on 5.7. If you're using syntax from a newer version on an older server, you'll see error 1064.
Advanced notes
In generated SQL (from ORMs, query builders, or templating), error 1064 often reveals issues in the generation logic. Check that your ORM is escaping identifiers correctly and using the right syntax for your MySQL version. For stored procedures and triggers, syntax errors prevent creation; validate the entire block before running. Character set and collation mismatches can sometimes appear as syntax errors in MySQL 5.7—ensure your connection charset matches the database.
Frequently asked questions
- What does "1064" mean?
- MySQL error 1064 (ER_PARSE_ERROR) is thrown when the MySQL parser encounters an SQL statement it cannot understand. This is not a runtime error—it occurs at the parsing stage before any query execution. The error means your SQL syntax violates MySQL rules or contains commands MySQL does not recognize.
- How do I fix "1064"?
- MySQL error 1064 indicates a syntax error in your SQL query. This happens when MySQL encounters mistyped commands, reserved words used as identifiers, incorrect punctuation, or deprecated syntax that it cannot parse.
- What causes "1064"?
- Typos or misspelled SQL keywords (e.g., SLECT instead of SELECT, INSRT instead of INSERT) Using MySQL reserved words as table or column names without backticks (e.g., select must be wrapped) Mismatched or missing parentheses, brackets, or quotes in the query
- Is the "1064" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.
Official resources & further reading
- 📚MySQL Official Documentation
- 📖MySQL Error Reference Manual(Official Docs)