1064 MySQL Origin: Data OSI layer 7 · Application Last updated 12 Oct 2026

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.

Exact message you may see You have an error in your SQL syntaxcheck the manual that corresponds to your MySQL server versionSQLSTATE[42000]: Syntax error or access violation: 1064
Seen on: MySQL PHP

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 FROM or )
  • 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. LIMIT in SQL Server, RETURNING in old MySQL)
  • Running a dump from a newer MySQL version on an older server

⚡ Quick fix

  1. Look just before the “near …” fragment
  2. Wrap identifiers in backticks: ` order `
  3. Use prepared statements instead of concatenating values
  4. Check syntax against your server version (SELECT VERSION();)

Detailed fix by platform

PHP

  1. 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

  1. 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

  1. Near — What fragment follows “near”?
  2. Before it — Missing comma/quote/keyword?
  3. Identifiers — Reserved words?
  4. Version — Syntax supported on this server?

🔧 Still not fixed?

Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:

Where this error sits

Origin: Data. Errors that are often confused with or caused by this one (click to open):

102 — SQL Server: Incorrect syntax near 'x'. (Msg 102) (SQL)1021054 — MySQL ERROR 1054 (42S22): Unknown column in 'field list' (MySQL)10541146 — MySQL ERROR 1146 (42S02): Table 'db.table' doesn't exist (MySQL)11461366 — MySQL ERROR 1366: Incorrect string value: '\xF0\x9F\x98\x80' for column (MySQL)136642601 — ERROR: syntax error at or near "x" (PostgreSQL)42601aggregate in WHERE — ERROR: aggregate functions are not allowed in WHERE (use HAVING) / MySQL 1111 Invalid use of group function (SQL)aggregate in WHEREambiguous column — Column reference is ambiguous / Column 'id' in field list is ambiguous (MySQL 1052) (SQL)ambiguous columnGROUP BY — Column must appear in the GROUP BY clause / isn't in GROUP BY (MySQL 1055 only_full_group_by) (SQL)GROUP BY1064

Explore the map of this error Full error map →

🧠 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.

💬 What worked for others

No tips yet — did something else fix this for you?

Share what worked for you

Tips are checked by an editor before they appear. Links are removed.