尝试插入新表时出现MySQL错误1064(42000)

时间:2019-09-01 11:36:25

标签: mysql

当我尝试运行时出现错误1064(42000):

 INSERT INTO ips (ip, created_at, lat, long, country, continent, city, postal_code, state) VALUES ('192.168.2.111', '2019-07-19 12:06:2', '40.3444', '50.44', 'test', 'test', 'test', 'test', 'test');

我使用以下命令创建了表:

CREATE TABLE `ips` ( `id` INT NOT NULL AUTO_INCREMENT, `ip` VARCHAR(255), `created_at` DATETIME, `lat` VARCHAR(255), `long` VARCHAR(255), `country` VARCHAR(255), `continent` VARCHAR(255), `city` VARCHAR(255), `postal_code` VARCHAR(255), `state` VARCHAR(255), PRIMARY KEY( `id` ));

我已经尝试使用`而不是'并将其放在各列中来运行它。我在这里缺少明显的东西吗?

1 个答案:

答案 0 :(得分:2)

longreserved word,必须在反引号中进行转义。试试这个:

 INSERT INTO ips (ip, created_at, lat, `long`, country, continent, city, postal_code, state) VALUES ('192.168.2.111', '2019-07-19 12:06:2', '40.3444', '50.44', 'test', 'test', 'test', 'test', 'test');

Demo on dbfiddle