Search code examples
mysqlsyntaxsyntax-error

What is the issue in the line "CREATE DATABASE Keys(" MYSQL


I was writing a MySQL table create statement when I encountered the following error with the following code:

You have an error in your SQL syntax; it seems the error is around: 'Keys( id INT PRIMARY KEY AUTO_INCREMENT, ip VARCHAR(45) NOT NULL, email VA' at line 1
CREATE TABLE Keys(
  id INT PRIMARY KEY AUTO_INCREMENT,
  ip VARCHAR(45) NOT NULL,
  email VARCHAR(255) NOT NULL
)

This code follows all MySQL guidelines as far as I know. Could anyone help me find out the error here?

Thanks!

I attempted to plug the code into various SQL syntax checkers and linters and I found the same error in all of the ones I tested.


Solution

  • KEYS is a MySQl reserved word, so the table name needs escaping. (Or changing, so this doesn't come up every time you make a query.)

    https://dev.mysql.com/doc/refman/8.0/en/keywords.html

    CREATE TABLE `Keys`(...)