简体   繁体   English

mysql-使用关键字作为列名时出现错误1064(42000)

[英]mysql - ERROR 1064 (42000) when using keywords as column name

What's wrong with this? 这怎么了 Ran this successfully on a Gentoo system, but now on a Debian-Squeeze (Raspberry PI) it won't work. 在Gentoo系统上成功运行了此操作,但现在在Debian-Squeeze(Raspberry PI)上无法运行。

Database is setup allright 数据库设置正确

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| arduino1           |
| mysql              |
| performance_schema |
| test               |
| tmp                |
+--------------------+
6 rows in set (0.01 sec)

mysql>

Command is: 命令是:

#mysql -u root -p******* arduino1 < arduino-tables.sql

Resulting in: 导致:

ERROR 1064 (42000) at line 1: 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 '(8),
    currentTime DATETIME,
    timeDiff INT(10),
    unixTime INT(10),
    currentR1 FL' at line 3

Content of arduino-tables.sql: arduino-tables.sql的内容:

#cat arduino-tables.sql:

CREATE TABLE pulseLog (
    id INT(10) UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
    timeStamp TIMESTAMP(8),
    currentTime DATETIME,
    timeDiff INT(10),
    unixTime INT(10),
    currentR1 FLOAT,
    currentS2 FLOAT,
    currentT3 FLOAT,
    currentAverageR1 FLOAT,
    currentAverageS2 FLOAT,
    currentAverageT3 FLOAT,
    temp0 FLOAT,
    temp1 FLOAT,
    temp2 FLOAT,
    temp3 FLOAT,
    temp4 FLOAT,
    temp5 FLOAT,
    pulses INT,
    event char(255),
 ) CHARACTER SET UTF8;

you are using keyword that is a datatype . 您使用的是datatype关键字。 you can do that by escaping it using backtick example 您可以使用backtick示例将其转义

CREATE TABLE pulseLog (
    id INT(10) UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
    `timeStamp` TIMESTAMP(8),
    `currentTime` DATETIME,
    `timeDiff` INT(10),
    `unixTime` INT(10),
    currentR1 FLOAT,
    currentS2 FLOAT,
    currentT3 FLOAT,
    currentAverageR1 FLOAT,
    currentAverageS2 FLOAT,
    currentAverageT3 FLOAT,
    temp0 FLOAT,
    temp1 FLOAT,
    temp2 FLOAT,
    temp3 FLOAT,
    temp4 FLOAT,
    temp5 FLOAT,
    pulses INT,
    event char(255),
 ) CHARACTER SET UTF8;

There where some typo errors, like timestamp is a key word, you had an extra comma after event char(255), . 在那里有一些拼写错误,例如timestamp是一个关键字,在event char(255),之后出现了一个逗号。

Try this: 尝试这个:

    CREATE TABLE pulseLog (
    id INT(10) UNSIGNED PRIMARY KEY NOT NULL AUTO_INCREMENT,
    `timeStamp` TIMESTAMP,
    `currentTime` DATETIME,
    `timeDiff` INT(10),
    `unixTime` INT(10),
    `currentR1` FLOAT,
    `currentS2` FLOAT,
    `currentT3` FLOAT,
    `currentAverageR1` FLOAT,
    `currentAverageS2` FLOAT,
    `currentAverageT3` FLOAT,
    `temp0` FLOAT,
    `temp1` FLOAT,
    `temp2` FLOAT,
    `temp3` FLOAT,
    `temp4` FLOAT,
    `temp5` FLOAT,
    `pulses` INT,
    `event` char(255)
 ) CHARACTER SET UTF8;

Here is the SQL Fiddle DEMO 这是SQL小提琴演示

Edit: 编辑:

Apart from that your syntax for timestamp was not supported. 除此之外,不支持时间戳的语法。 For reference on date, datetime and timestamp check here 有关日期,日期时间和时间戳的参考, 请在此处检查

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM