Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

What Is MySQL Error 1064 and How to Fix It

Understand the "You have an error in your SQL syntax" message and correct the query.

Fixing Errors3 min read

What the error means

MySQL error 1064 means the server could not understand your SQL statement. The full message looks like this:

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 1

The text after near shows where MySQL stopped reading. The real mistake is usually just before that point.

Causes

1. Reserved words

Using a MySQL keyword as a table or column name, such as order, group, key or desc, causes an error.

CREATE TABLE order (id INT);   -- error
CREATE TABLE `order` (id INT); -- works

Put names in back ticks, or choose other names.

2. Obsolete commands

Some old commands were removed in newer versions. For example TYPE=MyISAM in CREATE TABLE was replaced by ENGINE=MyISAM. Query cache and old PASSWORD() forms were also removed in MySQL 8.

3. Mistyped commands

A spelling mistake, a missing comma, quote or bracket, or a wrong order of the words:

SELEC * FROM users;            -- SELECT is misspelled
INSERT INTO users (name email) VALUES ('Ann', 'a@x.com');   -- missing comma

4. Missing data

A missing value, a missing closing quote or a missing semicolon in a script.

SELECT * FROM users WHERE name = ;

How to fix it

1. Correct the spelling and the syntax

Read the part of the query shown after near. Check commas, quotes, brackets and keywords. Make sure strings use straight quotes 'text', not curly quotes copied from a web page.

2. Replace obsolete commands

Check the MySQL manual of your version, and replace old syntax with the new one (ENGINE= instead of TYPE=).

3. Add the missing data

Make sure that each column has a value and each statement ends properly.

4. Check the version when you move a database

When you move a WordPress database from one server to another and import it, the dump may contain syntax that does not work in the new version. Fix this by exporting with a compatibility setting.

In phpMyAdmin, when you export, choose Custom and in Format-specific options set Database system or older MySQL server to maximize output compatibility with to MYSQL40 or another suitable value. Or use mysqldump --compatible=....

5. Use a tool

Paste the query into phpMyAdmin or MySQL Workbench. They highlight the error.

Common 1064 cases in WordPress

  • A plugin is not compatible with your MySQL version. Update or replace it.
  • A damaged import file. Export it again.
  • Special characters in the data that are not escaped. Use prepared statements in custom code.

Quick recap

  • Read the text after near, check the syntax, and quote reserved words with back ticks.