Knowledge

MySQL ERROR 1064: SQL syntax error

#Databases

Error 1064 means MySQL could not parse your query. The message points at exactly where parsing failed, the cause is usually a reserved word, a typo, or a quoting problem.

Published by Mark van Eijk on June 23, 2026 · 1 minute read

  1. About the error
  2. Why do I see this error
  3. Solution
  4. Read the "near" snippet
  5. Check quoting
  6. When it comes from application code

About the 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 '...' at line 1

The crucial part is the text after near. MySQL prints the query starting from the point where it got confused, so the problem is almost always at or just before that snippet, not somewhere else.

Why do I see this error

  • A reserved word used as a table or column name without backticks (order, group, rank, key, desc).
  • A typo in a keyword (SELCT, FORM, WHERE placed wrong).
  • A missing or mismatched quote or parenthesis.
  • A stray trailing comma before FROM or a closing bracket.
  • Mixing in another SQL dialect's syntax that MySQL doesn't accept, often when importing a dump made on a different server or version.

Solution

Read the "near" snippet

If you see near 'order (id int...', the word right after near (order) is the offender. ORDER is reserved, so quote it with backticks:

CREATE TABLE `order` (
  `id` INT PRIMARY KEY,
  `rank` INT
);

Backticks let you use reserved words as identifiers, though renaming the column to something non-reserved is cleaner long term.

Check quoting

Use single quotes for string values and backticks for identifiers, never the other way around:

-- wrong
SELECT * FROM users WHERE name = "O'Brien";
-- right
SELECT * FROM users WHERE name = 'O\'Brien';

When it comes from application code

If the query is built by your app, the syntax error usually means a variable was interpolated into the SQL unescaped, which is also a SQL injection risk. Use parameter binding instead of string concatenation. In Laravel, prefer the query builder or bindings:

DB::select('select * from users where email = ?', [$email]);

This both fixes the syntax problem and closes the injection hole.

If MySQL parses the query but can't find the table, that's a different error: base table or view not found. And once the query runs, the next question is usually whether it runs fast, see finding and optimizing slow MySQL queries.

Subscribe to our newsletter

Do you want to receive regular updates with fresh and exclusive content to learn more about web development, hosting, security and performance? Subscribe now!