एरर समाधान · डेवलपर एरर

MySQL ERROR 1064: You Have an Error in Your SQL Syntax

Decode MySQL ERROR 1064 syntax errors. Read the near clause, fix reserved words, quotes, trailing commas and version differences between MySQL and MariaDB.

Error messageERROR 1064 (42000): 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

लेखक: SiteDownCheck संपादकीय टीम · अपडेट: नवंबर 18, 2026 · 4 मिनट पढ़ने में

Error 1064 is the parser telling you it could not understand the statement. Nothing was executed. The useful part is the end of the message, which shows where parsing stopped.

ERROR 1064 (42000): 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
'order (id, total) VALUES (1, 9.99)' at line 1

MariaDB words it the same way, with "MariaDB server version". The text after near starts at the first token the parser could not accept. The mistake is usually at the very start of that quoted snippet or just before it.

How to read the message

  • If the snippet starts with a keyword like order, group or key, you probably used a reserved word as a name.
  • If the snippet is empty (near '' at line 1), the statement ended too early: a missing value, a dangling WHERE, or an unclosed quote or parenthesis.
  • The line number counts lines within the statement, not within your source file.
  • If the snippet shows something odd like \', ? or :name, the placeholder was never replaced by your driver.

Cause 1: reserved words as table or column names

order, group, key, desc, rank, index, release and many others are reserved. Wrap identifiers in backticks:

INSERT INTO `order` (`id`, `total`) VALUES (1, 9.99);

Better, rename the table to orders. The list differs by version (RANK and GROUPS became reserved in MySQL 8.0, which breaks some old schemas on upgrade). Check the keywords page in the manual for your version.

Backticks are MySQL-specific. Double quotes work for identifiers only when sql_mode includes ANSI_QUOTES; otherwise they delimit strings.

Cause 2: quoting and escaping errors

An unescaped apostrophe in a string ends it early:

-- Breaks
INSERT INTO notes (body) VALUES ('It's done');
-- Works
INSERT INTO notes (body) VALUES ('It''s done');

Never build SQL by concatenating user input. Use prepared statements with bound parameters, which fix both the syntax errors and SQL injection:

$stmt = $pdo->prepare('INSERT INTO notes (body) VALUES (:body)');
$stmt->execute([':body' => $text]);

If a query shows a literal $var or {$name} in the error snippet, string interpolation failed before the query was sent.

Cause 3: punctuation and structure

  • A trailing comma: SELECT id, name, FROM users or the last column in CREATE TABLE.
  • A missing comma between columns or values.
  • Unbalanced parentheses in a long WHERE ... AND (... OR ...).
  • LIMIT with a bound parameter in emulated-prepare PDO mode, where the number arrives quoted as '10'. Bind with PDO::PARAM_INT or turn off PDO::ATTR_EMULATE_PREPARES.
  • A missing DELIMITER change when creating stored procedures through the mysql client, so it splits the statement at the first semicolon.
  • Statements pasted from PostgreSQL or SQL Server: RETURNING, TOP 10, ::int casts, ILIKE, [brackets] and SERIAL are not valid MySQL.

Cause 4: version and engine differences

Syntax your local server accepts may not exist on the production one.

  • WITH common table expressions and window functions (OVER) need MySQL 8.0 or newer (CTEs also need MariaDB 10.2.1+, window functions 10.2.0+). On MySQL 5.7 they raise 1064.
  • CREATE TABLE ... GENERATED ALWAYS AS needs 5.7+.
  • ALTER TABLE ... ADD COLUMN IF NOT EXISTS works in MariaDB but not in MySQL.
  • JSON_TABLE, INSERT ... AS alias and CHECK constraint enforcement vary by version.
  • Collations such as utf8mb4_0900_ai_ci exist in MySQL 8 but not MariaDB; that normally gives a different error, but dumps moved between the two often fail near the COLLATE clause.

Run SELECT VERSION(); on the server that rejected the query, not the one on your laptop.

A debugging routine

  1. Copy the exact failing SQL from the log or from SHOW PROCESSLIST, with parameters filled in.
  2. Paste it into the mysql client against the same server.
  3. Cut the statement down until it works, then add parts back one at a time. The last thing you added is the culprit.
  4. For huge dump imports, the line number from the mysql client points at the statement. Use sed -n '1200,1210p' dump.sql to look at it.
  5. If a migration tool generated the SQL, turn on its query log, because you are debugging what was sent, not what you wrote.

Dumps from mysqldump can fail on import with 1064 if they were written by a newer server version with options such as SET @@SESSION.SQL_LOG_BIN or GTID statements an older server does not know. Re-dump with --set-gtid-purged=OFF where applicable, or remove those lines.

अगले कदम

सामान्य प्रश्न

Does error 1064 mean the database is broken?

No. It is a client-side mistake in the SQL text. The server and your data are unaffected.

Why does the same query work on my laptop?

Your laptop probably runs a different MySQL or MariaDB version, with different keywords and features. Compare SELECT VERSION(); on both.

Why does the error show near an empty string?

The parser reached the end of the statement while still expecting more, so look for a missing value, an unclosed quote, or a dangling clause.

Are backticks safe to use everywhere?

In MySQL and MariaDB, yes. They are not portable to PostgreSQL or SQL Server, so use an ORM or double-quote mode if you need portability.

Get notified when this fix updates

Plus occasional practical tips on uptime and monitoring, nothing else. Unsubscribe anytime.

यह पेज सामान्य जानकारी है, जिसे हमारी संपादकीय टीम ने लिखा है और दस्तावेज़ीकरण बदलने पर अपडेट किया जाता है। सर्वर और प्रदाता अलग-अलग होते हैं, इसलिए बदलाव पहले सुरक्षित तरीके से जाँचें। देखें: संपादकीय नीति और अस्वीकरण.