MySQL Error 1064: SQL Syntax Error (tested)
ERROR 1064 (42000): You have an error in your SQL syntax is MySQL's generic parse error — the statement couldn't even be understood, let alone run. Unlike most SQL errors, it doesn't name a table or column; instead it points at roughly where parsing broke down with "near '...'", which is usually your best clue.
1. Reading the error
The message always ends with near '...' at line N, showing the text MySQL was looking at when it gave up:
ERROR 1064 (42000) at line 1: 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 'id = 1' at line 1
Important: the text after "near" is where the parser noticed the problem, not necessarily where the mistake is. In this example the actual typo (WEHRE instead of WHERE) is a few characters before 'id = 1' — the parser only realises something is wrong once it hits the next token it can't make sense of.
2. Four reproduced causes
| Statement | Exact error |
|---|---|
SELECT * FROM users WEHRE id = 1; (typo'd keyword) | ... near 'id = 1' at line 1 |
CREATE TABLE t2 (id INT, order INT); (unquoted reserved word) | ... near 'order INT)' at line 1 |
SELECT id, name, FROM users; (trailing comma before FROM) | ... near 'FROM users' at line 1 |
SELECT * FROM users WHERE name = 'abc; (missing closing quote) | ... near ''abc' at line 1 |
3. Cause 1: a typo'd keyword
MySQL has no idea what WEHRE means, so it stops there and reports the next recognisable chunk (id = 1) as the "near" text. Read a few tokens before the quoted text, not just the quoted text itself.
4. Cause 2: a reserved word used unquoted
ORDER is a SQL keyword (used in ORDER BY), so MySQL can't use it as a bare column name:
mysql> CREATE TABLE t2 (id INT, order INT);
ERROR 1064 (42000) at line 1: ... near 'order INT)' at line 1
Fix: wrap it in backticks, MySQL's identifier-quoting character:
mysql> CREATE TABLE t2 (id INT, `order` INT);
Query OK, 0 rows affected
This works but is worth avoiding going forward — rename the column to order_id or similar if you can, since every future query against it will also need backticks.
5. Cause 3: a trailing comma
mysql> SELECT id, name, FROM users;
ERROR 1064 (42000) at line 1: ... near 'FROM users' at line 1
The comma after name tells MySQL to expect another column, so FROM is the unexpected token. This is the most common type of 1064 after a quick edit to a SELECT list (adding or removing a column and forgetting a comma).
6. Cause 4: an unterminated string
mysql> SELECT * FROM users WHERE name = 'abc;
ERROR 1064 (42000) at line 1: ... near ''abc' at line 1
The missing closing quote means everything after the opening ' — including the rest of your actual statement, and even a trailing ; — is swallowed as part of the string literal. If this happens with a string built from user input or a variable, check for an unescaped single quote inside the value itself (e.g. a name like O'Brien), which has the same effect.
7. How to track down the error fast
- Look at the token right after "near", then look a few tokens before it in your actual query — the real mistake is usually just before where parsing broke.
- Count your commas: every column in a SELECT list or every value in an INSERT needs exactly one comma between items, none after the last.
- If the "near" text starts mid-word or includes a stray quote, suspect an unterminated string literal.
- If the near-text is a single plain word that looks like a valid column name, suspect a reserved word (
order,group,key,index,tableare common ones) and wrap it in backticks or rename it. - Run the query in a client that shows the full multi-line statement with the error position, rather than building it as one long string in application code — it makes "near" text much easier to locate.
Frequently asked questions
Does the "near" text always show exactly where the mistake is?
No. It shows where the parser gave up, which is often a few tokens after the actual mistake. In our WEHRE typo test, the near text was 'id = 1' even though the real problem (the misspelled WHERE) came before it.
Why can't I use "order" as a column name?
It's a reserved SQL keyword (used in ORDER BY). We reproduced the exact failure with CREATE TABLE t2 (id INT, order INT) and confirmed the fix: wrapping it in backticks, `order` INT, which created the table successfully.
I'm building my SQL string in code and got 1064 — what's the most likely cause?
An unterminated string literal from unescaped input, most often a value containing a single quote (like O'Brien). We reproduced the same error shape by simply leaving off a closing quote: everything after it, including the real end of the statement, got swallowed into the string.
Is 1064 specific to MySQL?
The error code and exact wording are MySQL/MariaDB-specific. PostgreSQL reports syntax errors as ERROR: syntax error at or near "x" (see our PostgreSQL-based ambiguous-column and duplicate-key guides); SQL Server uses its own Msg numbers. The underlying problem — a statement the parser can't understand — is universal.
Why does a trailing comma cause an error instead of just being ignored?
SQL's grammar requires exactly one comma between each item and none after the last; a trailing comma makes the parser expect another column name, so the next keyword it actually finds (FROM, in our test) is reported as unexpected.
Written with AI assistance. Measured on 2026-10-03 with MySQL 8.4.11 (official Docker image), using the mysql CLI. Every error message below is copy-pasted output, not paraphrased. PlainHeaders is our extension; MySQL and Docker are free.