MySQL ERROR 1064 (42000): You have an error in your SQL syntax
MySQL couldn’t parse the query. The text after “near” shows where parsing failed.
Meaning
The quoted fragment after near is where MySQL got confused — the actual mistake is usually just before it. Reserved words used as column names, missing commas and wrong quote types are the usual suspects.
Common causes
- Reserved word as identifier (
order,group,key,rank,rows) without backticks - Missing/extra comma, especially before
FROMor) - String values not quoted, or using backticks/double quotes for strings
- Building SQL by string concatenation with unescaped quotes in data
- Syntax from another database (e.g.
LIMITin SQL Server,RETURNINGin old MySQL) - Running a dump from a newer MySQL version on an older server
⚡ Quick fix
- Look just before the “near …” fragment
- Wrap identifiers in backticks: `
order` - Use prepared statements instead of concatenating values
- Check syntax against your server version (
SELECT VERSION();)
Detailed fix by platform
PHP
- Prepared statements fix most quoting-related 1064s:php
$stmt = $pdo->prepare('INSERT INTO `orders` (`name`, `note`) VALUES (?, ?)'); $stmt->execute([$name, $note]); // quotes in $note can no longer break the SQL
MySQL
- Reserved words list: check MySQL “Keywords and Reserved Words” for your version (ROWS and RANK became reserved in 8.0).
Code examples
Reserved word
sql
SELECT id, order FROM sales; -- ❌ 1064 near 'order FROM sales'
SELECT id, `order` FROM sales; -- ✅How to diagnose
- Near — What fragment follows “near”?
- Before it — Missing comma/quote/keyword?
- Identifiers — Reserved words?
- Version — Syntax supported on this server?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026