0

我有以下 MySQL 查询:

INSERT INTO 12:12:12:12:12(timestamp,niceTime,temperature,relative_humidity,wind_speed,gust_speed,rain_mm_per_hour,nsew,str,ip) VALUES(1361707978,'2013-02-24T12:12:58+00:00',0.0,0,0.0,0.0,0.0,0,'1010101010101010','0')

表的名称是“12:12:12:12:12”。

这是架构:

"CREATE TABLE IF NOT EXISTS `$mac` (
  `timestamp` int(11) NOT NULL,
  `niceTime` varchar(20) NOT NULL,
  `temperature` float NOT NULL,
  `relative_humidity` int(11) NOT NULL,
  `wind_speed` float NOT NULL,
  `gust_speed` float NOT NULL,
  `rain_mm_per_hour` float NOT NULL,
  `nsew` int(11) NOT NULL,
  `str` varchar(1000) NOT NULL,
  `ip` varchar(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;"

无论我做什么,我都无法接受查询;(

Query failed: 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 '12:12:12:12:12(timestamp,niceTime,temperature,relative_humidity,wind_speed,gust_' at line 1

提前谢谢了,

4

2 回答 2

4

您将对表名 12:12:12:12:12 使用类似的反引号

尝试这个

   INSERT INTO `12:12:12:12:12`(timestamp,niceTime,temperature,relative_humidity,wind_speed,gust_speed,rain_mm_per_hour,nsew,str,ip) VALUES(1361707978,'2013-02-24T12:12:58+00:00',0.0,0,0.0,0.0,0.0,0,'1010101010101010','0'

编辑。

命名对象的规则,包括MySql中的表:

http://dev.mysql.com/doc/refman/5.1/en/identifiers.html

标识符可以以数字开头,但除非引用,否则标识符可能不仅仅由数字组成。

The identifier quote character is the backtick (“`”):
于 2013-02-24T12:33:35.973 回答
2

在标识符周围使用反引号,尤其是在使用此类非常规表名时:

INSERT INTO `12:12:12:12:12`(timestamp,niceTime,temperature,relative_humidity,wind_speed,gust_speed,rain_mm_per_hour,nsew,str,ip)
VALUES(1361707978,'2013-02-24T12:12:58+00:00',0.0,0,0.0,0.0,0.0,0,'1010101010101010','0')
于 2013-02-24T12:33:26.537 回答