Sharon Ben-Moshe is the founder of sqlfmt, a browser-based SQL formatter and validator with misspelled-keyword suggestions across PostgreSQL, MySQL, SQLite, SQL Server, and BigQuery.
"You have an error in your SQL syntax" (MySQL error 1064) means the parser hit an unexpected token. Here are the 7 common causes and how to fix each.
Quick answer
MySQL's "You have an error in your SQL syntax" (error 1064) means the parser found a token it can't accept near the text it quotes — the actual mistake is usually just before that point, not at it. The common causes are misspelled keywords, reserved words used as unquoted identifiers, missing or stray commas, the wrong quote characters, and deprecated syntax. Read the word right after "near" and inspect the token immediately before it.
FAQs
What is MySQL error 1064?
Error 1064 (ER_PARSE_ERROR) is the syntax error MySQL raises when its parser reaches a token that can't legally continue your statement. The query never runs, so no data is affected — it's purely a grammar problem in the SQL text you sent.
What does "near" mean in the MySQL syntax error?
"Near" quotes the token where MySQL stopped parsing. Because it parses left to right, that's the first point it couldn't continue — the real mistake is at that token or just before it, such as a missing comma on the previous line.
How do I fix error 1064 caused by a reserved word?
Wrap the identifier in backticks so MySQL treats it as a name rather than a keyword, for example `order` or `rank`. The list of reserved words grows between versions, so quoting all identifiers (or renaming them) avoids surprises after an upgrade.
Why does my query work in another database but throw 1064 in MySQL?
Each engine has its own grammar and reserved-word list. Syntax that's valid in PostgreSQL or SQL Server — different quoting, functions, or table options like TYPE= — can be rejected by MySQL's parser, producing error 1064.
Can a SQL formatter help me find syntax errors?
Yes. Formatting reflows your query so misplaced commas, unbalanced parentheses, and stray tokens become visible, and a validator like sqlfmt flags syntax errors and misspelled keywords before you ever send the query to MySQL.
Try it now
Paste your SQL into sqlfmt — format, validate, and catch typos free in your browser.
"You have an error in your SQL syntax" is MySQL telling you its parser choked on your query. It is error 1064 — the single most common error MySQL throws — and the fix is almost always small. The message quotes the text it failed "near", and the real mistake is usually the token right before that spot.
The error feels confusing because MySQL reports where it gave up, not where you went wrong. A missing comma three lines up surfaces as an error "near" the next keyword. Once you know how to read the message, the cause is nearly always one of a handful of patterns.
This post covers what the error means, how to read the "near" pointer, the seven causes that produce it, and a checklist to run before you hit Enter again. All examples are MySQL 8.x.
What "You have an error in your SQL syntax" actually means
The full message reads: "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 N". Internally it is error 1064 (ER_PARSE_ERROR), the catch-all the MySQL parser raises when it reaches a token that can't legally continue the statement. It is purely about grammar — the query never executed and touched no data.
The error you're trying to decode
ERROR 1064 (42000): You have an error in your SQL syntax;check the manual that corresponds to your MySQL server versionfor the right syntax to use near 'FROM users' at line 2
How do I read the "near" part of the error?
MySQL parses left to right and stops at the first token that can't continue a valid statement. The text after "near" is that token — so the mistake is at it or just before it. In the query below, MySQL reports the error near 'FROM users', but the actual problem is the trailing comma on the line above.
Broken: error reported near 'FROM users'
SELECT id, name,FROM users;
Fixed: drop the comma before FROM
SELECT id, nameFROM users;
The 7 most common causes of MySQL error 1064
1. A misspelled keyword
The classic. SELEC, WERE, and GORUP BY are not keywords, so the parser stops the moment it sees one. The error points right at the typo.
Broken: SELEC isn't a keyword
SELEC id, name FROM users;-- ...near 'SELEC id, name FROM users' at line 1
Fixed
SELECT id, name FROM users;
2. A reserved word used as an unquoted identifier
MySQL keeps a list of reserved words — names like order, rank, and groups — that can't be a table or column name unless you wrap them in backticks. The list grows between versions, so a name that worked in MySQL 5.7 can break after an upgrade (rank became reserved in 8.0).
3. A missing comma in a list
Drop a comma between two items in a column list or VALUES tuple and the parser sees two tokens jammed together where it expected a separator.
4. A trailing comma before a clause or closing paren
The opposite problem, and just as common — usually left behind after deleting the last column. MySQL does not allow a dangling comma before FROM, a closing parenthesis, or the end of a list.
5. Smart quotes or the wrong quote character
In MySQL, string values use straight single quotes and identifiers use backticks; see the identifier syntax rules. Pasting SQL from a doc, chat app, or word processor often swaps straight quotes for curly “smart” quotes, which the parser rejects outright.
6. Deprecated or version-specific syntax
Syntax removed in a newer MySQL throws 1064 even though it once worked. The TYPE= table option was removed in 5.5 in favor of ENGINE=; running a CTE or window function on MySQL 5.6 fails the same way because the grammar didn't exist yet.
7. An empty or truncated query from application code
When you build SQL by string interpolation, an empty or null variable produces a query that ends mid-clause. The tell-tale sign is an error near an empty string — "near ''". Log the final SQL string your code sends and the gap is obvious.
Other engines report the same class of problem with different wording. PostgreSQL says "syntax error at or near" and points just past the offending token the same way — our guide to fixing "syntax error at or near" in PostgreSQL walks through that dialect's version of this error.
A checklist to run before you execute the query again
Read the token right after "near" — your mistake is at it or just before it.
Check the reported line number, counting from line 1 of the statement, not the file.
Scan for a misspelled keyword: SELEC, FORM, WERE, GORUP BY, ODER BY.
Wrap any identifier that's a reserved word in backticks: `order`, `rank`, `groups`.
Confirm every list item is comma-separated — and that there's no comma before FROM or a closing paren.
Verify strings use straight single quotes ('…') and identifiers use backticks (`…`) — no curly quotes.
If the SQL came from code, log the final string and look for an empty interpolated variable.
Wrapping up
Error 1064 is almost always a small, locatable mistake: read the token after "near", inspect what comes just before it, and match it to one of the seven patterns above. The quickest way to catch these before MySQL does is to format and validate the query first — sqlfmt formats your SQL and flags syntax errors and misspelled keywords across MySQL and four other dialects in the browser, free to start. Formatting live as you type comes with Pro.