MySQL 8.4Lab-verified · 2026-12-01

MySQL ERROR 1064 (42000): You have an error in your SQL syntax

MySQL could not parse the statement; the text after near '…' is where parsing stopped.

MySQL 8.4.13
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 'rank INT, score INT)' at line 1

Jump to a cause

  1. 01A reserved word such as rank used as a column name
  2. 02A comma left before FROM
  3. 03GRANT ... IDENTIFIED BY on MySQL 8 (the 5.7 way to create a user)
  4. 04CREATE PROCEDURE without DELIMITER (semicolons inside BEGIN ... END)
  5. 05Table name wrapped in single quotes ('order')
  6. 06SQL Server syntax (TOP) in MySQL

Lab-verifiedReproduced and fixed on MySQL 8.4.13 · 2026-12-01 · container image mysql:8.4

The useful part of 1064 is the end of the message: near 'rank INT, score INT)' at line 1. Parsing failed at the first word of that quoted text, or right before it. The line number counts from the start of the statement.

So look at the first word inside near '…' and at what comes just before it. If the quoted text starts with FROM, the problem is usually at the end of the previous line.

01A reserved word such as rank used as a column name

RANK became a reserved word in MySQL 8.0 (window functions), so rank INT in CREATE TABLE fails, even though the same DDL worked on MySQL 5.7. information_schema.keywords shows RESERVED = 1. Check any suspicious name the same way.

Reproducerun as lab_a
CREATE TABLE scores (id INT PRIMARY KEY, rank INT, score INT);
✕ ERROR
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 'rank INT, score INT)' at line 1
Checkrun as lab_a
SELECT word, reserved FROM information_schema.keywords WHERE word = 'RANK';
OUTPUT
+------+----------+
| WORD | RESERVED |
+------+----------+
| RANK |        1 |
+------+----------+
1 row in set (0.00 sec)

Quote the name with backticks wherever it is used, or rename the column (for example ranking). With backticks the table was created and SHOW COLUMNS lists rank.

After the fixrun as lab_a
CREATE TABLE scores (id INT PRIMARY KEY, `rank` INT, score INT);
SHOW COLUMNS FROM scores;
✓ SUCCESS
Query OK, 0 rows affected (0.01 sec)

+-------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------+------+-----+---------+-------+
| id    | int  | NO   | PRI | NULL    |       |
| rank  | int  | YES  |     | NULL    |       |
| score | int  | YES  |     | NULL    |       |
+-------+------+------+-----+---------+-------+
3 rows in set (0.00 sec)

02A comma left before FROM

After removing a column from the SELECT list, a comma stays after email. MySQL then expects another column and finds FROM, so the message says near 'FROM users' at line 4. The mistake is at the end of line 3.

Setup
Setuprun as lab_a
CREATE TABLE users (id INT PRIMARY KEY, name VARCHAR(50), email VARCHAR(100));
INSERT INTO users VALUES (1, 'Kim', 'kim@example.com');
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 1 row affected (0.00 sec)
Reproducerun as lab_a
SELECT id,
       name,
       email,
FROM users;
✕ ERROR
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 'FROM users' at line 4
Checkrun as lab_a
SHOW COLUMNS FROM users;
OUTPUT
+-------+--------------+------+-----+---------+-------+
| Field | Type         | Null | Key | Default | Extra |
+-------+--------------+------+-----+---------+-------+
| id    | int          | NO   | PRI | NULL    |       |
| name  | varchar(50)  | YES  |     | NULL    |       |
| email | varchar(100) | YES  |     | NULL    |       |
+-------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)

Remove the comma after the last column. The same applies to a trailing comma before ) in CREATE TABLE or in a VALUES list.

After the fixrun as lab_a
SELECT id,
       name,
       email
FROM users;
✓ SUCCESS
+----+------+-----------------+
| id | name | email           |
+----+------+-----------------+
|  1 | Kim  | kim@example.com |
+----+------+-----------------+
1 row in set (0.00 sec)

03GRANT ... IDENTIFIED BY on MySQL 8 (the 5.7 way to create a user)

Following old 5.7 docs, GRANT ALL PRIVILEGES ON shop.* TO 'app_user'@'%' IDENTIFIED BY '...' fails with 1064 near IDENTIFIED BY. Since MySQL 8.0, GRANT no longer creates users and does not accept IDENTIFIED BY.

Setup
Setuprun as root
CREATE DATABASE shop;
OUTPUT
Query OK, 1 row affected (0.00 sec)
Reproducerun as root
GRANT ALL PRIVILEGES ON shop.* TO 'app_user'@'%' IDENTIFIED BY 'App#2026pw';
✕ ERROR
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 'IDENTIFIED BY 'App#2026pw'' at line 1
Check the causerun as root
SELECT VERSION() AS version;
SELECT user, host FROM mysql.user WHERE user = 'app_user';
OUTPUT
+---------+
| version |
+---------+
| 8.4.13  |
+---------+
1 row in set (0.00 sec)

Empty set (0.00 sec)

The version is 8.4.13 and mysql.user has no app_user (Empty set). The user has to be created first.

Fixrun as root
CREATE USER 'app_user'@'%' IDENTIFIED BY 'App#2026pw';
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Creating the user with CREATE USER 'app_user'@'%' IDENTIFIED BY '...' and then running GRANT without IDENTIFIED BY worked; SHOW GRANTS lists the privileges on shop.*.

After the fixrun as root
GRANT ALL PRIVILEGES ON shop.* TO 'app_user'@'%';
SHOW GRANTS FOR 'app_user'@'%';
✓ SUCCESS
Query OK, 0 rows affected (0.00 sec)

+----------------------------------------------------+
| Grants for app_user@%                              |
+----------------------------------------------------+
| GRANT USAGE ON *.* TO `app_user`@`%`               |
| GRANT ALL PRIVILEGES ON `shop`.* TO `app_user`@`%` |
+----------------------------------------------------+
2 rows in set (0.01 sec)

04CREATE PROCEDURE without DELIMITER (semicolons inside BEGIN ... END)

The mysql client sends everything up to a ; as one statement. So only CREATE PROCEDURE ... BEGIN UPDATE ... WHERE id = p_id; reached the server and failed with near '' at line 3 (the statement just ends). The leftover pieces ran on their own: the SELECT got Unknown column 'p_id' (1054) and the final END got another 1064.

Setup
Setuprun as lab_a
CREATE TABLE orders (id INT PRIMARY KEY, status VARCHAR(20));
INSERT INTO orders VALUES (1, 'NEW'), (2, 'PAID');
OUTPUT
Query OK, 0 rows affected (0.01 sec)

Query OK, 2 rows affected (0.00 sec)
Records: 2  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
CREATE PROCEDURE close_order(IN p_id INT)
BEGIN
  UPDATE orders SET status = 'CLOSED' WHERE id = p_id;
  SELECT id, status FROM orders WHERE id = p_id;
END;
✕ ERROR
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 '' at line 3
ERROR 1054 (42S22): Unknown column 'p_id' in 'where clause'
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 'END' at line 1
Fixrun as lab_a
DELIMITER //
CREATE PROCEDURE close_order(IN p_id INT)
BEGIN
  UPDATE orders SET status = 'CLOSED' WHERE id = p_id;
  SELECT id, status FROM orders WHERE id = p_id;
END //
DELIMITER ;
OUTPUT
Query OK, 0 rows affected (0.00 sec)

Switching the terminator with DELIMITER //, ending with END // and restoring DELIMITER ; created the procedure, and CALL close_order(1) set order 1 to CLOSED. DELIMITER is a mysql client command; tools that send the whole statement to the server may not need it.

After the fixrun as lab_a
CALL close_order(1);
✓ SUCCESS
+----+--------+
| id | status |
+----+--------+
|  1 | CLOSED |
+----+--------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

05Table name wrapped in single quotes ('order')

To use the reserved word order as a table name, the query wrapped it in single quotes, INSERT INTO 'order' ..., and failed near 'order' (id, amount) .... In MySQL, single quotes make a string value, which cannot stand where a table name goes.

Setup
Setuprun as lab_a
CREATE TABLE `order` (id INT PRIMARY KEY, amount INT);
OUTPUT
Query OK, 0 rows affected (0.01 sec)
Reproducerun as lab_a
INSERT INTO 'order' (id, amount) VALUES (1, 5000);
✕ ERROR
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, amount) VALUES (1, 5000)' at line 1
Checkrun as lab_a
SHOW TABLES;
OUTPUT
+-----------------+
| Tables_in_lab_a |
+-----------------+
| order           |
+-----------------+
1 row in set (0.00 sec)

Quote identifiers (table and column names) with backticks. INSERT INTO order ... inserted the row.

After the fixrun as lab_a
INSERT INTO `order` (id, amount) VALUES (1, 5000);
SELECT * FROM `order`;
✓ SUCCESS
Query OK, 1 row affected (0.00 sec)

+----+--------+
| id | amount |
+----+--------+
|  1 |   5000 |
+----+--------+
1 row in set (0.00 sec)

06SQL Server syntax (TOP) in MySQL

SELECT TOP 2 is SQL Server syntax. MySQL reads TOP as a column name and then fails at 2 name, …. SELECT VERSION() confirms you are on MySQL (8.4.13 here). Syntax copied from examples for other databases fails the same way.

Setup
Setuprun as lab_a
CREATE TABLE products (id INT PRIMARY KEY, name VARCHAR(50), price INT);
INSERT INTO products VALUES (1, 'pen', 1000), (2, 'book', 15000), (3, 'bag', 30000);
OUTPUT
Query OK, 0 rows affected (0.02 sec)

Query OK, 3 rows affected (0.00 sec)
Records: 3  Duplicates: 0  Warnings: 0
Reproducerun as lab_a
SELECT TOP 2 name, price FROM products ORDER BY price DESC;
✕ ERROR
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 '2 name, price FROM products ORDER BY price DESC' at line 1
Checkrun as lab_a
SELECT VERSION();
OUTPUT
+-----------+
| VERSION() |
+-----------+
| 8.4.13    |
+-----------+
1 row in set (0.00 sec)

Use MySQL's LIMIT at the end: ORDER BY price DESC LIMIT 2. This returned bag and book.

After the fixrun as lab_a
SELECT name, price FROM products ORDER BY price DESC LIMIT 2;
✓ SUCCESS
+------+-------+
| name | price |
+------+-------+
| bag  | 30000 |
| book | 15000 |
+------+-------+
2 rows in set (0.00 sec)

FAQ

How do I fix MySQL error 1064 You have an error in your SQL syntax?

Look at the text after near in the message. The error is at its first word or just before it (often a missing or extra comma, a reserved word, or syntax from another database).

Why does my CREATE TABLE fail with 1064 on MySQL 8 but worked on 5.7?

A column name became a reserved word in MySQL 8.0, such as rank. Check it in information_schema.keywords, then put the name in backticks or rename the column.

What is the MySQL equivalent of SELECT TOP?

LIMIT at the end of the query: SELECT … ORDER BY … LIMIT 2.

Why does the error point at FROM when FROM is correct?

MySQL reports where parsing stopped, not where the mistake is. With a comma left after the last column, the message says near 'FROM users', but the fix is at the end of the previous line.

GRANT ... IDENTIFIED BY gives ERROR 1064 on MySQL 8

Since 8.0, GRANT cannot create users. Run CREATE USER 'user'@'host' IDENTIFIED BY 'password' first, then GRANT without IDENTIFIED BY. That is what worked in the test.

Why does CREATE PROCEDURE fail with 1064 near '' at line 3?

The mysql client cut the statement at the first ; inside BEGIN. Set DELIMITER //, end the body with END //, then restore DELIMITER ;.

How we verify

Each scenario starts from fresh database users. A script runs the setup, confirms the exact error code, applies the fix and runs the statement again. The output shown is what the database printed, saved by the script.

lab_a and lab_b are ordinary users created for the test, each with full rights on a database of the same name (its default database); root is the administrator. MySQL 8.4.13