2

这有什么问题?在 Gentoo 系统上成功运行了这个,但现在在 Debian-Squeeze (Raspberry PI) 上它不会工作。

数据库设置好了

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

mysql>

命令是:

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

导致:

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

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;
4

2 回答 2

2

那里有一些拼写错误,比如timestamp一个关键字,你在 . 之后有一个额外的逗号 event char(255),

尝试这个:

    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;

这是SQL Fiddle 演示

编辑:

除此之外,不支持您的时间戳语法。有关日期、日期时间和时间戳的参考,请在此处查看

于 2012-09-11T10:05:26.263 回答
2

您正在使用的关键字是datatype. 您可以通过使用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;
于 2012-09-11T09:59:37.877 回答