MySQL 1064 error — exact message:
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 NMySQL cannot parse the SQL you submitted. The fragment shown in quotes marks exactly where parsing stopped — start your diagnosis there.
The MySQL 1064 error is a syntax error: MySQL received a SQL statement it could not parse. The error message always includes the line number and the query fragment that triggered the failure — both are your fastest diagnostic clues. Common causes:
- Incorrect syntax — a typo, missing comma, or misplaced keyword.
- Spelling errors —
SLECTinstead ofSELECT,WHERinstead ofWHERE. - Reserved words — using
order,table, orkeyas column or table names without backticks. - Unmatched parentheses — an unclosed
(or an extra)in a subquery. - Missing or incorrect data — a variable in the query is empty or contains an unexpected value.
- Outdated syntax — commands from older MySQL versions (
TYPE=MyISAM,CHARSET=latin1) that fail on newer servers.
Contents
Which Cause Do I Have?
Use this table to identify the most likely cause before diving into the fixes:
| Your symptom | Most likely cause | Fix |
|---|---|---|
Error message mentions a SQL keyword (ORDER, KEY, TABLE, INDEX, DATABASE) as the problem word |
Reserved word used as column or table name without backticks | Fix 4: Escape Reserved Words |
Error points to a line number near a ( or ) |
Parenthesis mismatch | Fix 2: Check Parentheses |
| Error appeared after importing a database dump or upgrading MySQL | Outdated syntax in the dump (TYPE=MyISAM, CHARSET=latin1) |
Fix 6: Update Outdated Commands |
| A dynamic query worked before but now fails; query contains a PHP variable | Empty or missing variable value | Fix 5: Address Missing Data |
The problematic token is a misspelled keyword (SLECT, INSRET, WHER) |
Spelling error | Fix 3: Fix Spelling |
| None of the above — general query structure problem | Syntax issue in query structure | Fix 1: Check Syntax |
Resolving the MySQL 1064 Error
1. Double-Check Your Syntax
MySQL’s error message tells you the exact character position where parsing stopped. Read the quoted fragment in the error, then look at the SQL immediately before that point. The most common structural problems:
- Missing comma between column definitions in
CREATE TABLE - A semicolon inside a stored procedure body that ends the entire statement prematurely
- A keyword used in the wrong clause (
WHEREinstead ofHAVINGon an aggregate query)
Before/after example — missing comma:
-- Broken: no comma after the first column definition
CREATE TABLE users (
id INT NOT NULL
username VARCHAR(50)
);
-- Fixed
CREATE TABLE users (
id INT NOT NULL,
username VARCHAR(50)
);
2. Pay Attention to Parentheses
Every opening parenthesis needs a matching closing one. Subqueries and IN (...) clauses are the most common source of parenthesis imbalance — especially when editing a query by hand or assembling it from parts.
Before/after example — unclosed subquery:
-- Broken: missing closing ) for the IN subquery
SELECT * FROM orders WHERE user_id IN (
SELECT id FROM users WHERE active = 1
;
-- Fixed
SELECT * FROM orders WHERE user_id IN (
SELECT id FROM users WHERE active = 1
);
3. Spelling Errors: A Common Culprit
MySQL does not attempt to autocorrect a misspelled keyword — it stops parsing immediately and returns a 1064 error. A single transposed character in SELECT, INSERT, UPDATE, WHERE, or any other reserved word triggers this.
Before/after example — misspelled SELECT:
-- Broken
SLECT id, name FROM users;
-- Error: ... near 'SLECT id, name FROM users'
-- Fixed
SELECT id, name FROM users;
A robust SQL Syntax Checker catches these typos before you run the query against a live database.

Here, it identifies the error and specifies the line containing the error.
4. Properly Escape Reserved Words
MySQL reserves certain words for its own syntax: ORDER, TABLE, KEY, INDEX, DATABASE, SELECT, FROM, WHERE, and many others. Using any of them as a table or column name without backticks causes a 1064 error. The fix is to wrap the identifier in backticks.
Before/after example — reserved word as table name:
-- Broken: ORDER is a MySQL reserved word
SELECT name FROM order WHERE id = 1;
-- Error: ... near 'order WHERE id = 1'
-- Fixed: backticks tell MySQL this is an identifier, not a keyword
SELECT name FROM `order` WHERE id = 1;
CREATE TABLE `order` (...Different versions of MySQL have different reserved word lists. When migrating a database from an older MySQL version, a word that was safe in MySQL 5.7 may be reserved in MySQL 8.0. Check the MySQL Reference Manual for your target version and run a find-and-replace on the dump before importing.
5. Addressing Missing Data
If a PHP variable that feeds into a SQL query is empty or unset, the assembled SQL becomes malformed. A query like WHERE id = (with nothing after the =) is valid PHP string concatenation but invalid SQL.
Before/after example — empty variable:
// $orderId is empty — the POST field was not submitted
$orderId = $_POST['order_id'] ?? '';
// Resulting SQL is broken:
// SELECT * FROM orders WHERE id =
$sql = "SELECT * FROM orders WHERE id = $orderId";
Validate the variable before building the query:
// Fixed: validate before use
if (empty($orderId) || !is_numeric($orderId)) {
return; // do not run a malformed query
}
$sql = "SELECT * FROM orders WHERE id = " . intval($orderId);
To diagnose this in a live WordPress environment, open phpMyAdmin or Adminer, navigate to the SQL query panel, and run the query with a known-good literal value to confirm the syntax is correct in isolation. If it passes there, the issue is in how the variable is populated, not in the query structure itself.
6. Upgrading Outdated Commands
MySQL syntax changes between major versions. Database dumps generated on MySQL 5.x frequently contain syntax that fails immediately on MySQL 8.x servers. The two most common causes in WordPress site migrations:
TYPE=MyISAM (removed; use ENGINE=InnoDB):
-- Broken on MySQL 5.5+ (TYPE= keyword was removed)
CREATE TABLE wp_options (
option_id BIGINT(20) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (option_id)
) TYPE=MyISAM;
-- Fixed
CREATE TABLE wp_options (
option_id BIGINT(20) NOT NULL AUTO_INCREMENT,
PRIMARY KEY (option_id)
) ENGINE=InnoDB;
DEFAULT CHARSET=latin1 on strict MySQL 8:
Older dumps specify CHARSET=latin1. On MySQL 8.0 with character_set_server=utf8mb4 and sql_mode=STRICT_TRANS_TABLES, this can produce a 1064 on the CREATE TABLE line. Fix the dump before importing:
-- Find in the dump file:
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- Replace with:
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
From WP STAGING support tickets, the most common 1064 trigger on WordPress migrations is an old dump that contains TYPE=MyISAM — it fails on the first CREATE TABLE and aborts the entire import. A find-and-replace in a text editor before running the import resolves it immediately.
To confirm the MySQL version your server is running:
SELECT VERSION();
Consult the MySQL Reference Manual for a full list of removed and changed syntax between versions.

What to Do If the Fix Doesn’t Work
If you’ve worked through all six causes and the 1064 error persists, use this checklist to isolate the root cause:
- Confirm you’re connected to the correct database. Run
SHOW TABLES;to verify the table you’re querying exists and is named exactly as your query expects — including the WordPress table prefix. - Verify your MySQL version:If the query syntax requires a newer MySQL version than what’s installed, upgrade MySQL or rewrite the query for the installed version.
- Check the WordPress table prefix. WordPress tables use the prefix defined in
wp-config.php(commonlywp_). A query that hard-codeswp_optionsfails if the actual prefix iswpstg_or something else. - Isolate the failing clause. Strip the query to its simplest form — remove joins, subqueries, and
WHEREclauses one at a time until the 1064 disappears. The last clause you removed is the cause. - Enable WordPress debug logging. If the 1064 originates from a plugin or theme, enabling
WP_DEBUGandWP_DEBUG_LOGcaptures the full query with its stack trace. See how to enable WordPress debug log mode — the log entry will name the exact function generating the malformed query.
Conclusion
The MySQL 1064 error always traces back to one specific cause: a typo, a reserved word used without backticks, a parenthesis mismatch, a missing variable, or outdated syntax in a database dump. MySQL’s error message gives you the line number and the exact fragment where parsing failed — that is your starting point. Apply the matching fix above, and use the troubleshooting checklist if the first attempt doesn’t resolve it.