MySQL & MariaDB error 1064: You have an error in your SQL syntax
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 '('Reset0pw!') WHERE user= (8.0.46) · You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'c WHERE c.sessionid = 1 (10.6.28) The parser could not understand the statement. The text after "near" is where it gave up, and the real mistake is usually just before it.
| MySQL | MariaDB | |
|---|---|---|
| Symbol | ER_PARSE_ERROR | ER_PARSE_ERROR |
| SQLSTATE | 42000 | 42000 |
| Type | Server error | Server error |
| Versions | every release since 5.0 active | every release since 5.5 active |
What it means
1064 is the parser’s general “I can’t read this” error. It doesn’t say what is wrong, only where parsing stopped: …for the right syntax to use near 'salary FROM emp WHERE' at line 1. The mistake is almost always immediately before the quoted text. If the quoted text is empty (near '' at line 1), the statement ended too early.
Why it happens
- A missing or extra comma, bracket or quote.
- A reserved word used as a table or column name. Words become reserved over time:
RANK,ROWS,GROUPS,FUNCTION,SYSTEMand 22 others became reserved in MySQL 8.0, soSELECT salary AS rankworks on 5.7 and fails with 1064 on 8.0. See the reserved words by version. - Syntax from another database or another version:
TOP 10(SQL Server),ALTER IGNORE TABLE(removed in MySQL 5.7),GRANT … IDENTIFIED BY(removed in MySQL 8.0), window functions on MySQL 5.7. - Statements meant for the
mysqlcommand-line client (DELIMITER $$,source file.sql) sent through an application driver, which sends them to the server literally. - Smart quotes (
‘ ’ “ ”) pasted from a document instead of plain'and".
How to fix it
- Look at the text right before the
near '…'part, and check commas, brackets and quotes there. - Put backticks around any identifier that could be a keyword:
SELECT salary AS `rank` FROM emp. Use the reserved words table when upgrading. - Check the statement is valid for your version:
SELECT VERSION(); - Drop
DELIMITERlines when running a procedure definition through a driver; send theCREATE PROCEDUREas one statement.
Reproduce it yourself
These steps are the exact test our harness runs. Use a scratch server, never production.
Connect with
mysql -u root -pand create a scratch database and the test data:CREATE DATABASE demo; USE demo; CREATE TABLE emp (id INT, name VARCHAR(20), salary INT); INSERT INTO emp VALUES (1,'Ann',100),(2,'Bob',200);Run:
SELECT id name, salary FROM emp WHERE;
You get: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1(11.8.9)
Verified fixes
Quote reserved words with backticks
SELECT name, salary AS `rank` FROM emp ORDER BY id;
Tested on
| Step | MySQL | MariaDB | |||||||
|---|---|---|---|---|---|---|---|---|---|
| 5.6 | 5.7 | 8.0 | 8.4 | 9 | 10.6 | 10.11 | 11.4 | 11.8 | |
| A missing comma between columns repro | ✓ 1064 | ✓ 1064 | ✓ 1064 | ✓ 1064 | ✓ 1064 | ✓ 1064 | ✓ 1064 | ✓ 1064 | ✓ 1064 |
| A column alias that became a reserved word (RANK in MySQL 8.0) version check | ≠ | ≠ | ✓ 1064 | ✓ 1064 | ✓ 1064 | ≠ | ≠ | ≠ | ≠ |
| Quote reserved words with backticks fix | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ | ✓ |
What the warnings and failures say (1)
- A column alias that became a reserved word (RANK in MySQL 8.0) (MySQL 5.6, MySQL 5.7, MariaDB 10.6, MariaDB 10.11, MariaDB 11.4, MariaDB 11.8): expected error 1064 did not occur
Related errors
Where this error shows up in our guides
- Triggers · Two BEFORE UPDATE triggers on one table (FOLLOWS) MySQL 5.6
- Triggers · CREATE TRIGGER IF NOT EXISTS MySQL 5.6 5.7
- Triggers · CREATE OR REPLACE TRIGGER MySQL 5.6 5.7 8.0 8.4 9
- Copying a database, users and privileges between two servers · SHOW CREATE USER + SHOW GRANTS for 5 users, drop them, replay (MySQL 8.0+ hashes contain random binary bytes) MySQL 5.6
- Writing dynamic SQL in stored procedures · PREPARE from a local (DECLAREd) variable MySQL 5.6 5.7 8.0 8.4 9
- Writing dynamic SQL in stored procedures · EXECUTE IMMEDIATE MySQL 5.6 5.7 8.0 8.4 9
- Drop foreign key constraint · ALTER TABLE ... DROP CONSTRAINT child_ibfk_1 (MySQL 8.0.19+, MariaDB 10.2+) MySQL 5.6 5.7
- Running totals/determine row position · Row position with ROW_NUMBER() OVER (modern) MySQL 5.6 5.7
- Running totals/determine row position · Running total with SUM() OVER (modern) MySQL 5.6 5.7
- Renumber field values · UPDATE ... JOIN (999 + ROW_NUMBER() OVER (ORDER BY id)) (modern) MySQL 5.6 5.7
- Counting repetitions in a specific order · Gaps-and-islands with ROW_NUMBER() (MySQL 8.0+, MariaDB 10.2+) MySQL 5.6 5.7
- Splitting fields · Recursive CTE (MySQL 8.0+, MariaDB 10.2+) MySQL 5.6 5.7
- Splitting fields · JSON_TABLE (MySQL 8.0.4+, MariaDB 10.6+) MySQL 5.6 5.7
- Stored procedures and dynamic SQL · Post's note: PREPARE from a local VARCHAR fails MySQL 5.6 5.7 8.0 8.4 9
- Stored procedures and dynamic SQL · No dynamic SQL: JSON array of titles with JSON_TABLE (MySQL 8.0+, MariaDB 10.6+) MySQL 5.6 5.7
- Resetting lost root password · --skip-grant-tables + UPDATE mysql.user SET password=PASSWORD() (pre-5.7 recipe) MySQL 8.0 8.4 9
- Resetting lost root password · --skip-grant-tables + UPDATE mysql.user SET authentication_string=PASSWORD() (5.7 recipe) MySQL 8.0 8.4 9
- Resetting lost root password · --skip-grant-tables + FLUSH PRIVILEGES; ALTER USER ... IDENTIFIED BY (modern) MySQL 5.6
- Resetting lost root password · --skip-grant-tables + FLUSH PRIVILEGES; SET PASSWORD FOR ... = PASSWORD('x') MySQL 8.0 8.4 9
- Minimum privileges to take a backup · GRANT ... IDENTIFIED BY (original) MySQL 8.0 8.4 9
- DELETE with a join · DELETE FROM carts c WHERE ... (alias in single-table DELETE) MySQL 5.6 5.7MariaDB 10.6 10.11 11.4
- FULL OUTER JOIN · Native FULL OUTER JOIN syntax MySQL 5.6 5.7 8.0 8.4 9MariaDB 10.6 10.11 11.4 11.8
- Update table with new id values · UPDATE ... JOIN (ROW_NUMBER() OVER ...) (MySQL 8.0+, MariaDB 10.2+) MySQL 5.6 5.7
- INTO OUTFILE and headers · SELECT 'Name',... UNION SELECT * INTO OUTFILE ... FROM t1 (original) MariaDB 10.6 10.11 11.4 11.8
- INTO OUTFILE and headers · Parenthesised second SELECT with INTO OUTFILE and ORDER BY (original) MariaDB 10.6 10.11 11.4 11.8
- Adding unique constraint · ALTER IGNORE TABLE ... ADD PRIMARY KEY (original) MySQL 5.7 8.0 8.4 9
- Adding unique constraint · ALTER IGNORE TABLE ... ADD UNIQUE KEY (same idea, unique index) MySQL 5.7 8.0 8.4 9
- Adding unique constraint · ALTER IGNORE TABLE ... ADD UNIQUE KEY on a NOT NULL column MySQL 5.7 8.0 8.4 9
- Adding unique constraint · De-duplicate with ROW_NUMBER() then add PK (modern) MySQL 5.6 5.7
- Implementing MINUS in MySQL · Native EXCEPT (modern) MySQL 5.6 5.7
- Implementing MINUS in MySQL · MINUS keyword, default sql_mode MySQL 5.6 5.7 8.0 8.4 9MariaDB 10.6 10.11 11.4 11.8
- Implementing MINUS in MySQL · MINUS keyword with sql_mode = ORACLE (MariaDB) MySQL 5.6 5.7
- Runtime values · Compute the balance at query time with SUM() OVER (MySQL 8.0+, MariaDB 10.2+) MySQL 5.6 5.7
- Update rank on a table · SELECT ... AS rank with @rank / @ctryid (original) MySQL 8.0 8.4 9
- Update rank on a table · UPDATE ... INNER JOIN (SELECT ... AS rank ...) (original) MySQL 8.0 8.4 9
- Update rank on a table · UPDATE ... JOIN (ROW_NUMBER() OVER (PARTITION BY country_id)) (modern) MySQL 5.6 5.7
- Get time difference between successive records · Difference using LAG() OVER (ORDER BY starttime) (modern) MySQL 5.6 5.7
- Removing duplicate records · ALTER IGNORE TABLE ... ADD UNIQUE INDEX (original) MySQL 5.7 8.0 8.4 9
- Removing duplicate records · Add a temporary id, delete with ROW_NUMBER(), add UNIQUE (modern) MySQL 5.6 5.7
- Ranking Columns · @Rank := @Rank + 1 AS rank (original) MySQL 8.0 8.4 9
- Ranking Columns · Dense rank with CASE and @prev_Age (original) MySQL 8.0 8.4 9
- Ranking Columns · RANK() / DENSE_RANK() OVER (ORDER BY age) (modern) MySQL 5.6 5.7
- How to generate a timeline based on duration · Running total with SUM() OVER (MySQL 8.0+, MariaDB 10.2+) MySQL 5.6 5.7
- How to generate a timeline based on duration · Window version with a 5 second gap between songs MySQL 5.6 5.7
How the message changed between versions
| MariaDB from | Symbol | Message |
|---|---|---|
| 5.5.68 | ER_PARSE_ERROR | %s near '%-.80s' at line %d |
| 10.2.44 | ER_PARSE_ERROR | %s near '%-.80T' at line %d |
| 11.8.10 | ER_PARSE_ERROR | %s near '%-.80sT' at line %d |