1064 🐬 MySQL

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.

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