How to fix ERROR 1064: You have an error in your SQL syntax in MySQL

MySQLBEGINNERMEDIUMUpdated Dec 25, 2025· 749 views

MySQL Error 1064 (ER_PARSE_ERROR) occurs when the database parser encounters invalid SQL syntax. Common causes include misspelled keywords, unescaped reserved words, mismatched quotes or parentheses, missing data values, and outdated syntax. Fixing requires careful review of the query, using backticks for reserved words, and validating syntax with tools.

Quick fix

Fixes 1064

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 'WHERE' at line 3
  1. Read the error message carefully to locate the problem area
  2. Check for misspelled SQL keywords
  3. Escape reserved words with backticks
  4. Verify parentheses, commas, and quote balance
mysql — error
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 'WHERE' at line 3
ERROR 1064: You have an error in your SQL syntax

What this error means

MySQL Error 1064 is a parsing error that indicates the MySQL server cannot understand your SQL statement because it violates SQL syntax rules. The error 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 '...' at line X". The snippet in quotes shows where MySQL stopped parsing—this location points to the first token it found unexpected. This is crucial for debugging, as the actual error may be slightly before this position (often a missing comma or misspelled keyword that throws off subsequent parsing). Error 1064 is purely about syntax—it is not related to missing tables, wrong permissions, or server configuration. It means the SQL text itself is malformed. The MySQL parser enforces strict syntax rules, and even small mistakes like missing spaces, extra commas, or incorrect use of reserved words trigger this error.

Typical symptoms

  • Query execution fails immediately with ERROR 1064 message
  • The error message snippet ("near '...' at line X") highlights a confusing location in your query
  • Simple SELECT queries fail even though they look correct visually
  • INSERT, UPDATE, or DELETE statements are rejected
  • Application throws "syntax error" message when submitting data
  • Query works in one MySQL version but fails after upgrading
  • Queries with special characters or reserved words as column names fail

Common causes

  1. Misspelled SQL keywords: SELEC instead of SELECT, WERE instead of WHERE, INSRT instead of INSERT
  2. Using reserved words (SELECT, FROM, WHERE, INSERT, UPDATE, DELETE, etc.) as table or column names without backticks
  3. Unbalanced or mismatched parentheses in WHERE clauses, function calls, or subqueries
  4. Missing or misplaced commas between column lists or value lists
  5. Unescaped or mismatched quotes around string values (missing opening or closing quote)
  6. Using single/double quotes around identifiers instead of backticks (MySQL-specific)
  7. Deprecated or removed syntax from older MySQL versions
  8. Missing required data or parameters in INSERT statements (e.g., empty value after equals sign)
  9. Data type mismatches when inserting incompatible data types

How to fix "ERROR 1064: You have an error in your SQL syntax"

1Read the error message carefully to locate the problem area

The error message includes a snippet showing where MySQL parser failed. This is your first clue.

bash
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 'WHERE' at line 3

In this example, "WHERE" is the first unexpected token. The actual error is likely just before WHERE (missing comma in the SELECT list, for example). Look 1-3 tokens before the quoted snippet.

Check what you see:
- "near 'FROM'": Problem in the SELECT clause (missing comma?)
- "near a reserved word": That word needs backticks if used as an identifier
- "near end of statement": Missing closing parenthesis or unnecessary trailing comma

2Check for misspelled SQL keywords

Typos in keywords are the single most common cause of Error 1064.

sql
-- WRONG (typo: SELEC instead of SELECT)
SELEC * FROM users;

-- CORRECT
SELECT * FROM users;

-- WRONG (typo: WERE instead of WHERE)
SELECT * FROM users WERE id = 1;

-- CORRECT
SELECT * FROM users WHERE id = 1;

Common misspellings to watch for:
- SELEC, SELCT → SELECT
- FORM → FROM
- WERE, WEHERE → WHERE
- INSRT, INSTERT → INSERT
- UPDAET, UPDAT → UPDATE
- DELTE → DELETE
- CREAT → CREATE

3Escape reserved words with backticks

If your table or column names are SQL reserved words, MySQL requires backticks (not single or double quotes).

sql
-- WRONG (using double quotes or no escaping)
SELECT "select" FROM "from";
SELECT select FROM from;

-- CORRECT (using backticks)
SELECT `select` FROM `from`;

-- Also correct in some contexts
SELECT `order`, `group`, `user` FROM `table`;

MySQL reserves hundreds of keywords (SELECT, INSERT, FROM, WHERE, ORDER, GROUP, JOIN, etc.). If you use them as identifiers, always use backticks.

To check if a word is reserved, search the MySQL documentation or use single backticks when in doubt—it will not hurt correct identifiers.

4Verify parentheses, commas, and quote balance

Unbalanced delimiters cause parsing to fail.

sql
-- WRONG (missing closing parenthesis)
SELECT COUNT(*) FROM users WHERE id IN (1, 2, 3;

-- CORRECT
SELECT COUNT(*) FROM users WHERE id IN (1, 2, 3);

-- WRONG (missing comma after column)
SELECT id name email FROM users;

-- CORRECT
SELECT id, name, email FROM users;

-- WRONG (mismatched quotes)
SELECT * FROM users WHERE name = 'John;

-- CORRECT
SELECT * FROM users WHERE name = 'John';

For complex queries with nested subqueries, count opening and closing parentheses in pairs. Many SQL editors highlight matching delimiters—use this feature.

5Check INSERT and UPDATE statements for complete value lists

INSERT and UPDATE require complete syntax with no missing values.

sql
-- WRONG (incomplete VALUES clause)
INSERT INTO users (id, name, email) VALUES (1, 'John');

-- CORRECT (all values provided)
INSERT INTO users (id, name, email) VALUES (1, 'John', 'john@example.com');

-- WRONG (missing value after equals)
UPDATE users SET name = WHERE id = 1;

-- CORRECT
UPDATE users SET name = 'Jane' WHERE id = 1;

For multi-row inserts, ensure each row has the same column count and proper formatting.

6Use an SQL validator tool or MySQL Workbench

Online tools and IDE features can catch syntax errors before execution.

bash
# In MySQL Workbench:
# 1. Paste your query in the SQL editor
# 2. Use Ctrl+Shift+Enter to syntax check
# 3. Red underlines show errors
# 4. Hover for error details

Online validators:
- EverSQL (https://www.eversql.com/)
- SQL Fiddle (http://sqlfiddle.com/)
- Metabase SQL debugger (https://www.metabase.com/learn/sql/debugging-sql/)

Copy your query into these tools—they highlight syntax errors and suggest corrections before you run the query on your database.

7Verify MySQL version compatibility

Syntax rules differ between MySQL versions. Older syntax may not work in newer versions and vice versa.

sql
-- Check your MySQL version:
SELECT VERSION();
SELECT @@version;

-- Example: TYPE keyword (deprecated, use ENGINE)
-- WRONG (MySQL 5.5+):
CREATE TABLE users (id INT) TYPE=InnoDB;

-- CORRECT (MySQL 5.5+):
CREATE TABLE users (id INT) ENGINE=InnoDB;

If your query worked in MySQL 5.7 but fails in 8.0, consult the "What's New" section of the MySQL 8.0 manual. Common deprecations are documented in release notes.

For migration projects, test queries on target MySQL version before deploying code.

Advanced notes

For complex queries, the error location may be misleading—MySQL sometimes reports the error at the first invalid token downstream of the actual mistake. For a query with syntax error in the first clause, the error message might point to a much later clause where the parser first realized something was wrong.

When debugging complex SELECT statements with JOINs, subqueries, and CTEs (Common Table Expressions), break the query into smaller parts and test each part independently. This isolates which clause has the syntax error.

MySQL 8.0 introduced strict SQL mode by default (sql_mode includes STRICT_TRANS_TABLES, STRICT_ALL_TABLES, etc.). This mode rejects more ambiguous syntax than earlier versions. If upgrading causes Error 1064 on previously working queries, check the error log and compare against MySQL 8.0 strict mode rules.

In application code, use prepared statements (parameterized queries) with placeholders instead of string concatenation. This prevents SQL injection and reduces syntax errors from quoting issues: SELECT * FROM users WHERE id = ? (with parameter binding) instead of string interpolation.

For debugging in development, enable the MySQL general query log temporarily to see exactly what SQL your application sends: SET GLOBAL general_log = 'ON';. This reveals any formatting issues in dynamically generated queries.

Frequently asked questions

What does "1064" mean?
MySQL Error 1064 is a parsing error that indicates the MySQL server cannot understand your SQL statement because it violates SQL syntax rules. ' at line X". The snippet in quotes shows where MySQL stopped parsing—this location points to the first token it found unexpected.
How do I fix "1064"?
MySQL Error 1064 (ER_PARSE_ERROR) occurs when the database parser encounters invalid SQL syntax. Common causes include misspelled keywords, unescaped reserved words, mismatched quotes or parentheses, missing data values, and outdated syntax. Fixing requires careful review of the query, using backticks for reserved words, and validating syntax with tools.
What causes "1064"?
Misspelled SQL keywords: SELEC instead of SELECT, WERE instead of WHERE, INSRT instead of INSERT Using reserved words (SELECT, FROM, WHERE, INSERT, UPDATE, DELETE, etc.) as table or column names without backticks Unbalanced or mismatched parentheses in WHERE clauses, function calls, or subqueries
Is the "1064" error serious?
It is a medium-severity error — more of a blocker than a risk. The steps above resolve it.

Official resources & further reading