簡體   English   中英

mysql-使用關鍵字作為列名時出現錯誤1064(42000)

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

這怎么了 在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;

您使用的是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;

在那里有一些拼寫錯誤,例如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小提琴演示

編輯:

除此之外,不支持時間戳的語法。 有關日期,日期時間和時間戳的參考, 請在此處檢查

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM