MySQL Error 1064: You Have an Error in Your SQL Syntax Updated on December 31, 2025 by Carrie Smaha 8 Minutes, 57 Seconds to Read MySQL Error 1064 appears when the database engine cannot parse your SQL statement. The error message typically reads: “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 X.” The good news: this error always points to a specific location in your query. The text after “near” shows exactly where MySQL stopped understanding your command, and the line number tells you where to look. How to Read the Error Message Before fixing anything, extract the diagnostic information MySQL provides. A typical 1064 error 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 'FORM users WHERE id = 1' at line 1ERROR 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 'FORM users WHERE id = 1' at line 1 Three pieces of information matter here: The snippet after “near” shows the first characters MySQL could not interpret. In this example, “FORM” is the problem; it should be “FROM.” The line number indicates where the parser stopped. In multi-line queries, this narrows your search. The 42000 code is the SQLSTATE value, which confirms this is a syntax-class error. If your query spans dozens of lines, copy it into a text editor with line numbers before troubleshooting. Common Causes of MySQL Error 1064 Misspelled Commands Typos are the most frequent cause of syntax errors. MySQL commands must match exactly. Typos like “SELCT,” “UDPATE,” and “FORM” all trigger Error 1064. Broken query: UDPATE customers SET status = 'active' WHERE id = 5;UDPATE customers SET status = 'active' WHERE id = 5; Working query: UPDATE customers SET status = 'active' WHERE id = 5;UPDATE customers SET status = 'active' WHERE id = 5; The fix is straightforward, but these typos hide easily in longer queries. Reading your SQL aloud or using a syntax checker catches mistakes your eyes skip over. Reserved Words as Identifiers MySQL reserves certain words for specific functions. In the MySQL 8.0 Reference Manual, reserved words are permitted as identifiers if you quote them using backticks. Broken query: CREATE TABLE order (id INT, date DATE, total DECIMAL(10,2));CREATE TABLE order (id INT, date DATE, total DECIMAL(10,2)); MySQL interprets “order” as the ORDER BY clause, not a table name. Working query: CREATE TABLE `order` (id INT, `date` DATE, total DECIMAL(10,2));CREATE TABLE `order` (id INT, `date` DATE, total DECIMAL(10,2)); Backticks tell MySQL to treat these words as identifiers rather than commands. Both “order” and “date” are reserved words, so both need quoting. You can check whether a word is reserved by querying the INFORMATION_SCHEMA: SELECT * FROM INFORMATION_SCHEMA.KEYWORDS WHERE WORD = 'ORDER';SELECT * FROM INFORMATION_SCHEMA.KEYWORDS WHERE WORD = 'ORDER'; The KEYWORDS table lists the words considered keywords by MySQL and, for each one, indicates whether it is reserved. A better long-term solution: avoid reserved words entirely. Name the table “orders” or “customer_orders” instead. Missing or Extra Punctuation SQL syntax requires specific punctuation in specific places. Missing commas between column definitions, unmatched parentheses, or absent semicolons all produce Error 1064. Broken query (missing comma): CREATE TABLE products ( id INT AUTO_INCREMENT PRIMARY KEY name VARCHAR(100), price DECIMAL(10,2) );CREATE TABLE products ( id INT AUTO_INCREMENT PRIMARY KEY name VARCHAR(100), price DECIMAL(10,2) ); Working query: CREATE TABLE products ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), price DECIMAL(10,2) );CREATE TABLE products ( id INT AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100), price DECIMAL(10,2) ); That surprises a lot of developers on their first encounter. The error message points to “name VARCHAR(100)” because MySQL expected a comma or closing parenthesis before it. Mismatched Quotes String values require quotes, and the opening and closing quotes must match. Single quotes (') enclose string literals in MySQL. Backticks (`) surround identifiers. Double quotes (") behave differently depending on the SQL mode. Broken query: SELECT * FROM users WHERE name = 'O'Brien';SELECT * FROM users WHERE name = 'O'Brien'; The apostrophe in “O’Brien” terminates the string early. Working query: SELECT * FROM users WHERE name = 'O''Brien';SELECT * FROM users WHERE name = 'O''Brien'; Doubling the single quote escapes it. Alternatively, use a backslash: 'O\'Brien'. SELECT * FROM users WHERE name = 'O\'Brien';SELECT * FROM users WHERE name = 'O\'Brien'; Missing Data in Variables When application code builds SQL queries dynamically, empty variables create incomplete statements. Query with missing variable: SELECT * FROM users WHERE user_id = ;SELECT * FROM users WHERE user_id = ; If your application substitutes a variable for the user ID and that variable is empty, the query reaches MySQL with nothing after the equals sign. MySQL cannot parse an incomplete comparison. What your application should generate: SELECT * FROM users WHERE user_id = 42;SELECT * FROM users WHERE user_id = 42; Check your application logs and variable assignments. If you use prepared statements, which you should for security reasons, the database driver typically catches these issues before they become syntax errors. Obsolete Commands MySQL removes deprecated commands after a transition period. The most common example is the TYPE keyword for storage engines. Outdated query: CREATE TABLE archive (id INT) TYPE = InnoDB;CREATE TABLE archive (id INT) TYPE = InnoDB; The TYPE keyword was deprecated in MySQL 4.1 and removed entirely in MySQL 5.1. Current query: CREATE TABLE archive (id INT) ENGINE = InnoDB;CREATE TABLE archive (id INT) ENGINE = InnoDB; This issue frequently appears when importing database dumps created on older MySQL versions. If you are migrating from MySQL 5.x to 8.x, you can encounter problems when you attempt to replicate from an older source to a newer replica and you make use of identifiers on the source that are reserved words in the newer MySQL version. Version Incompatibility MySQL adds new reserved words with each major release. A column named “rank” works fine in MySQL 5.7 but fails in MySQL 8.0, where RANK became a reserved word for window functions. Check your MySQL version: SELECT VERSION();SELECT VERSION(); Then compare your identifiers against the reserved words list for your version. Character Encoding Issues Copy-pasting SQL from word processors or websites sometimes introduces invisible characters or “smart quotes” that look correct but are not ASCII. SELECT * FROM users WHERE status = ‘active’;SELECT * FROM users WHERE status = ‘active’; Those curly quotes render beautifully in documentation but MySQL does not recognize them. Replace them with straight single quotes: SELECT * FROM users WHERE status = 'active';SELECT * FROM users WHERE status = 'active'; If you suspect encoding problems, paste your query into a plain text editor or hex viewer to expose hidden characters. How to Fix MySQL Error 1064 Step 1: Locate the Error Position Find the snippet shown after “near” in the error message. That text marks where parsing failed. The actual mistake usually appears just before that point. Step 2: Check for Typos Compare each keyword in your query against the official syntax. Spell out SELECT, FROM, WHERE, UPDATE, INSERT, DELETE, and other commands letter by letter if needed. Step 3: Verify Punctuation Confirm that: Every opening parenthesis has a closing match Commas separate column definitions and value lists String literals use straight single quotes Semicolons terminate statements, especially in multi-statement scripts Step 4: Escape Reserved Words If your table or column names match MySQL reserved words, wrap them in backticks. Better yet, rename them to avoid the conflict permanently. Step 5: Validate Dynamic Queries Print the final SQL string your application generates before execution. Variables that appear correct in your code may produce invalid SQL after concatenation. Step 6: Test with Simpler Queries Break complex queries into smaller pieces. Execute each piece separately until you find the segment that fails. This isolates the problem faster than staring at 50 lines of SQL. Online Syntax Checkers Running your query through a syntax validator before execution saves time, especially for long or complex statements. These tools parse SQL without connecting to a database: EverSQL SQL Validator ExtendsClass SQL Validator Beekeeper Studio Syntax Checker The validation rules adjust based on the dialect you select from the dropdown menu. Select MySQL specifically rather than generic SQL for accurate results. phpMyAdmin also highlights syntax errors before execution if you enable the SQL validator feature. Preventing Error 1064 Use Prepared Statements Prepared statements separate SQL structure from data values. This eliminates a whole class of syntax errors from variable interpolation while also protecting against SQL injection: $stmt = $pdo->prepare("SELECT * FROM users WHERE email = ?"); $stmt->execute([$email]);$stmt = $pdo->prepare("SELECT * FROM users WHERE email = ?"); $stmt->execute([$email]); Adopt Naming Conventions Prefix table names with a category identifier (e.g., “tbl_order” or “app_order”) to avoid collisions with reserved words. Use snake_case for multi-word names: “user_accounts” rather than “UserAccounts” or “user-accounts.” Version Your Schema Scripts When upgrading MySQL, test your existing queries against the new version in a development environment first. Reserved word conflicts and deprecated syntax surface quickly in testing but cause production outages if discovered after migration. Keep Database Tools Updated Database management tools like phpMyAdmin, MySQL Workbench, and DBeaver include updated syntax highlighting and autocompletion that reflect current MySQL versions. Outdated tools may suggest deprecated syntax. Special Cases Importing Database Dumps Large SQL dump files often contain multiple statements and comments. A single syntax error halts the entire import. If you encounter Error 1064 during import: Open the dump file in a text editor Search for the text shown in the error message Fix the statement and retry the import For dumps from older MySQL versions, search for “TYPE=” and replace with “ENGINE=“. Stored Procedures and Functions Stored procedure definitions contain multiple statements, which requires changing the delimiter temporarily: DELIMITER // CREATE PROCEDURE GetUserCount() BEGIN SELECT COUNT(*) FROM users; END // DELIMITER ;DELIMITER // CREATE PROCEDURE GetUserCount() BEGIN SELECT COUNT(*) FROM users; END // DELIMITER ; Without the DELIMITER change, MySQL interprets the first semicolon as the end of the CREATE PROCEDURE statement, producing a syntax error. Running SQL from Programming Languages When you see Error 1064 from application code, log the complete SQL string immediately before execution. Driver libraries sometimes modify queries, and seeing the exact text MySQL receives reveals problems hidden in your source code. Error 1064 Summary MySQL Error 1064 indicates a syntax problem at a specific location in your query. The error message identifies where parsing failed, and the cause is almost always one of these issues: Misspelled commands Reserved words used without backticks Missing commas, quotes, or parentheses Empty variables in dynamically built queries Obsolete commands from older MySQL versions Methodical checking, starting from the position MySQL identifies and working backward, resolves most cases within minutes. For persistent problems, syntax validators and simplified test queries isolate the issue faster than reviewing the full statement repeatedly. If you manage WordPress or other database-driven applications on your own server, having reliable hosting with 24/7 human support helps when database issues arise unexpectedly. Our VPS Hosting includes managed MySQL with expert assistance available around the clock. Share this Article Carrie Smaha Senior Manager Marketing Operations Carrie Smaha is a Senior Marketing Operations leader with over 20 years of experience in digital strategy, web development, and IT project management. She specializes in go-to-market programs and SaaS solutions for WordPress and VPS Hosting, working closely with technical teams and customers to deliver high-performance, scalable platforms. At InMotion Hosting, she drives product marketing initiatives that blend strategic insight with technical depth. More Articles by Carrie Related Articles How to Fix the Insecure SSL Error due to SHA-1 Deprecation MySQL Error 1064: You Have an Error in Your SQL Syntax MySQL Error 1044 Access Denied Troubleshooting: Fixing the “localhost Refused to Connect” Error HTTP Error Codes: What They Mean and How to Fix Them How to Fix the 504 Gateway Timeout Error 500 Internal Server Error How to Fix the “550 No Such User Here” Email Error Email Error – Mailbox Quota Exceeded Resolving DNS_PROBE_FINISHED_NXDOMAIN Errors
02252024 Hello, These conversations were informative. But I got these error messages after I migrated from Joomla 3.10 to Joomla 4 & 5 below as shown in this link: http://tinyurl.com/y9dx6xhh “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 ‘ AND `null` = ‘NO” at line 1” And “There are tables not up to date!” Is there a fix for this? Thank you. Joseph Lariosa
Hello everyone, I have a php website with laravel framework. The problem is every now and then randomly images gets deleted from my website basically from the storage folder. I have set the permissions for folders and sub-folders to 775 but still it happens. What could be the issue? can anyone help?
I recommend reviewing the cPanel logs for any record of these files being accessed or edited. For example, your access logs or FTP logs may show the files being deleted or modified by a specific user. If you need assistance with this our Live Support team can provide a copy or help you search the logs.
Hello i have an error here can u pleas help me? 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 ‘0) VALUES (Array)’ at line 1 INSERT INTO `dtl_peminjaman` (0) VALUES (Array)
It’s difficult to say without knowing the exact setup of your database, but you may not need to have single quotation marks around your table name and there would typically be a column name within the first parenthesis. For more information, I recommend reviewing the official MySQL documentation on the INSERT Statement, as it provides full details and examples.
Hello i have an error here can u pleas help me? SELECT password FROM users WHERE password=” or ‘ 1=1’; “ERROR: (1064, “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 ‘1=1”’ at line 1″)”
Hello Someone – Sorry for the issue with the SQL statement. You’re using the WHERE clause incorrectly. You need to be explicit when you’re defining it. Here’s an example (with OR): SELECT * FROM Customers WHERE City=’Berlin’ OR City=’München’; Start with that, and if you’re still having issues with your code, I suggest speaking with an experienced SQL developer for further assistance.
$mysql=”INSERT INTO `ITEMS` VALUES (‘”.$itemid.”‘, ‘2210010001’, ‘001’, ‘”.$postdata[“itemname”].”‘, ‘”.$postdata[“itemdescription”].”‘, ‘”.$postdata[“aboutthis”].”‘, ‘”.$postdata[“aprice”].”‘, ‘”.$postdata[“dprice”].”‘, ‘”.$postdata[“itemlink”].”‘, ’76’, ’43’, ‘Y’)”; $result = mysqli_query($con, $mysql); if($result) $remarks=”New Added Successfully. ID=”.$itemid; else $remarks=”“.mysqli_error($con).”:“.$mysql; echo “remarks : “.$remarks; RESULT remarks : 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 ‘INSERT INTO `ITEMS` VALUES (‘221004091058001’, ‘2210010001’, ‘001’, ”, ‘ at line 1: INSERT INTO `ITEMS` VALUES (‘221004091058001’, ‘2210010001’, ‘001’, ”, ”, ”, ‘4’, ‘5’, ‘6’, ’76’, ’43’, ‘Y’)
Anand – all the code checkers confirm that there is a syntax issue in the INSERT INTO area of your code. The MySQL 8.0 reference provides these instructions for the INSERT command (https://dev.mysql.com/doc/refman/8.0/en/insert.html). You may need to speak with a database programmer if you require further assistance.
Please I’m a newbie and i’m using the alain Beaulieu book ‘Learning SQL’ and on the first tutorial we need to add this function after creating the database ‘bank’. I have created it and typed the code but the shell returns the error after this code : mysql>grant all privileges on bank.* to ‘lrngsql’@’localhost’ identified by ‘xyz’; 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 ‘xyz” at line 1
Here is a link to some helpful documentation on the GRANT statement, I don’t believe you would need the “identified by ‘xyz’;” section. This seems to be part of a CREATE USER statement possibly.
Hello Nigglestein – The code you’re using in the terminal may not apply to MySQL the way that you’re seeing it in your text. This may depend on the type of account that you have and the permissions you have for the MySQL database. The error does indicate a syntax issue. We would have to look directly at the code you used to see what’s wrong. You can also reference the command here: https://dev.mysql.com/doc/refman/8.0/en/grant.html. The easier way to apply ALL privileges per account is to create a MySQL database in cPanel. When you create the database, you will have an option to add the permissions to the user assigned to the account. (Create DB through cPanel: https://www.inmotionhosting.com/support/edu/cpanel/how-to-create-a-mysql-database-using-the-cpanel-api/).
ALTER TABLE employees ADD CONSTRAINT `employees_cons_1` FOREIGN KEY (`reportsTo`) REFERENCES `employees` (`employeeNumber`), CONSTRAINT `employees_cons_2` FOREIGN KEY (`officeCode`) REFERENCES `offices` (`officeCode`); #1064 – 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 ‘CONSTRAINT `employees_cons_2` FOREIGN KEY (`officeCode`) REFERENCES `offices`…’ at line 3
Your “Add Constraint” does not seem to be formatted correctly, typically it would be followed by a name such as: ADD CONSTRAINT name Here is a helpful link to some documentation on the ALTER TABLE statement, it provides some helpful examples.
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 ”4846280,01-01-1978 )’ at line 1
Hello Shmooke – Sorry for the problem with your MySQL(Maria DB) error. As the error states, it’s a syntax error, meaning that there’s a problem with either command or formatting of your code. Without the exact code, we can’t identify where the problem is located. We advise that you use a SQL code parser like the examples provided in the article. They will be able to help you narrow down where the error is occurring. Otherwise, you should speak with an experienced database programmer.
no ,it has not touched my problem,and this is the problem below 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 ‘Keys’ at line 1 i want to create a database and it is telling me that.
Hi, Jacob! Sorry to hear that you’re running into trouble here. How exactly are you creating the database? Is this part of the installation of some software, or through cPanel’s database utility?
I created a drop down list of states in the HTML form using data set present in the table named cool in my database in phpmyadmin. Names of states are present in the table “cool”. Now I created another table called “data” to store the user input values of name, address, contact and the email ID. I created a third table named “tab” which consists of ID and the stat columns to store the name of the state when the user selects from the drop down list. Now i tried joining tables “data” and “tab” using inner join in SQL. When I fetched the data and tried printing it in another web page , the name, email, contact and address are getting printed but the ID of the state in the table “cool” is getting printed instead of the name of state. I tried a lot to get the name of the state but always in vain. I request you to help me fix this problem and print the name of the state instead of it’s ID in the web page !!
Hello Sravya, Your issue is a coding one with your database. We do not provide support for coding, so I recommend that you speak with an experienced developer or programmer. You can also find many tutorials for MySQL online that may provide the information you seek. Apologies that we cannot provide a direct solution for your issue.
I get this error when trying to import a database to phpmyadmin Error Static analysis: 3 errors were found during analysis. Variable name was expected. (near ” ” at position 5) Variable name was expected. (near ” ” at position 26) Unrecognized statement type. (near “Host” at position 0) SQL query: Copy Host: localhost (Version: 5.6.16) # Date: 2015-06-03 23:46:52 # Generator: MySQL-Front 5.3 (Build 4.122) /*!40101 SET NAMES utf8 */ MySQL said: Documentation #1064 – 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 ‘Host: localhost (Version: 5.6.16) # Date: 2015-06-03 23:46:52 # Generator: My’ at line 1 phpmy admin seemingly has a problem with this: # Host: localhost (Version: 5.6.16) # Date: 2015-06-03 23:46:52 # Generator: MySQL-Front 5.3 (Build 4.122) /*!40101 SET NAMES utf8 */;
ERROR 1064 (42000) at line 6: 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 ‘ <link rel' at line 1 Operation failed with exitcode 1
Hello, Saikat! It looks like there is an issue with how the query is coded. Unfortunately, we are unable to provide direct support for coding questions, so I recommend that you speak with an experienced developer or programmer. That said, I’d start by examining the early link syntax to see if it might be something simple like a missing comma or semi-colon. Apologies that we cannot provide a direct solution for your issue.
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 ‘default(Cus_name,Rs_status,Acc_type,Acc_class,Currency,Init_deposit,Dob,Gender,M’ at line 1. this error how to solve plz help me
Hello Sandar – sorry for the syntax error. We would need to see more of the MySQL query in order to determine the problem. I would recommend that you speak with an experienced developer or review your code to find the syntax issue that is causing the error to appear.
Hi I got this error when trying to import mysql database into phpmyadmin using a local XAMPP server. Please what probably go wrong? Error: Static analysis: 10 errors were found during analysis. Unexpected character. (near “{” at position 224) Unexpected beginning of statement. (near “DOCTYPE” at position 2) Unexpected beginning of statement. (near “HTML” at position 10) Unexpected beginning of statement. (near “html” at position 16) Unexpected beginning of statement. (near “lang” at position 21) Unexpected beginning of statement. (near “‘en'” at position 26) Unexpected beginning of statement. (near “dir” at position 31) Unexpected beginning of statement. (near “‘ltr'” at position 35) Unexpected beginning of statement. (near “meta” at position 42) Unrecognized statement type. (near “charset” at position 47) SQL query: html{display: none MySQL said: Documentation #1064 – 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 ‘<meta name="ref' at line 1
Hi Oluwatobi, The error indicates there is an issue with your syntax. This depends on your version of MySQL. I recommend that you review the documentation for the version of MySQL you are using to ensure you have the proper syntax in your code.
Hey I got this error and I tried so many ways to fix it but I could not so can any one help me to figure it out ! This is the error : Static analysis: 1 errors were found during analysis. Unexpected beginning of statement. (near “id11897681_admin” at position 0) SQL query: id11897681_admin SET time_zone = “+00:00” MySQL said: Documentation #1064 – 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 ‘id11897681_admin SET time_zone = “+00:00″‘ at line 1
Sorry for the problem that you’re getting with the SQL Syntax. I’m not 100% sure of the issue but it appears to be possible syntax near the ID you’re using. The documentation shows three backticks before the timezone. Check it out in the MariaDB’s official documentation: https://mariadb.com/kb/en/library/time-zones/.