[mysql] MySQl Error #1064

I keep getting this error:

MySQL said: #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 'INSERT INTO books.book(isbn10,isbn13,title,edition,author_f_name,author_m_na' at line 15

with this query:

USE books;

DROP TABLE IF EXISTS book;


    CREATE TABLE `books`.`book`(
    `book_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
    `isbn10` VARCHAR(15) NOT NULL,
    `isbn13` VARCHAR(15) NOT NULL,
    `title` VARCHAR(50) NOT NULL,
    `edition` VARCHAR(50) NOT NULL,
    `author_f_name` VARCHAR(50) NOT NULL,
    `author_m_name` VARCHAR(50) NOT NULL,
    `author_l_name` VARCHAR(50) NOT NULL,
    `cond` ENUM('as new','very good','good','fair','poor') NOT NULL,
    `price` DECIMAL(8,2) NOT NULL,
    `genre` VARCHAR(50) NOT NULL,
    `quantity` INT NOT NULL)

    INSERT INTO books.book(isbn10,isbn13,title,edition,author_f_name,author_m_name,author_l_name,cond,price,genre,quantity)** 
    VALUES ('0136061699','978-0136061694','Software Engineering: Theory and Practice','4','Shari','Lawrence','Pfleeger','very good','50','Computing','2');

Any idea what the problem is?

This question is related to mysql mysql-error-1064

The answer is


Sometimes when your table has a similar name to the database name you should use back tick. so instead of:

INSERT INTO books.book(field1, field2) VALUES ('value1', 'value2');

You should have this:

INSERT INTO `books`.`book`(`field1`, `field2`) VALUES ('value1', 'value2');

At first you need to add semi colon (;) after quantity INT NOT NULL) then remove ** from ,genre,quantity)**. to insert a value with numeric data type like int, decimal, float, etc you don't need to add single quote.


In my case I was having the same error and later I come to know that the 'condition' is mysql reserved keyword and I used that as field name.


Examples related to mysql

Implement specialization in ER diagram How to post query parameters with Axios? PHP with MySQL 8.0+ error: The server requested authentication method unknown to the client Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver' phpMyAdmin - Error > Incorrect format parameter? Authentication plugin 'caching_sha2_password' is not supported How to resolve Unable to load authentication plugin 'caching_sha2_password' issue Connection Java-MySql : Public Key Retrieval is not allowed How to grant all privileges to root user in MySQL 8.0 MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client

Examples related to mysql-error-1064

How to grant all privileges to root user in MySQL 8.0 Warning about SSL connection when connecting to MySQL database How can I fix MySQL error #1064? MySQL Error #1133 - Can't find any matching row in the user table MySql Inner Join with WHERE clause Check for database connection, otherwise display message ERROR 1064 (42000) in MySQL mysql is not recognised as an internal or external command,operable program or batch MySQL error: 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 SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax — PHP — PDO