'2013-08-25T17:00:00+00:00'
这是有效的iso-8601 datetime值,但不是有效的MySQL datetime文字。在这一点上,开发人员是不正确的。
该文档解释了ALLOW_INVALID_DATES
做什么:
仅检查月份范围是1到12,日期范围是1到31。
换句话说,2013-02-31
如果allow_invalid_dates
设置的话,将是一个允许的日期。当日期或日期时间甚至不是MySQL的有效格式时,此选项也不执行任何操作。
该+00:00
是时区偏移从UTC。在这种情况下,时间是表示在 UTC,所以偏移为零小时,零分钟。
您的解决方法是STRICT_TRANS_TABLES
从sql_mode
MySQL 5.6安装过程中创建的配置文件中的默认设置中删除。您需要仔细考虑更改此设置的含义,但它确实允许数据进入。
mysql> select @@sql_mode;
+--------------------------------------------+
| @@sql_mode |
+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+
1 row in set (0.00 sec)
mysql> insert into datetimetest(dt) values ('2013-08-26T12:00:00+00:00');
ERROR 1292 (22007): Incorrect datetime value: '2013-08-26T12:00:00+00:00' for column 'dt' at row 1
-- remove STRICT_TRANS_TABLES -- note that executing this only removes it for your
-- current session -- it does not make a server-wide config change
mysql> set @@sql_mode='no_engine_substitution';
Query OK, 0 rows affected (0.00 sec)
mysql> select @@sql_mode;
+------------------------+
| @@sql_mode |
+------------------------+
| NO_ENGINE_SUBSTITUTION |
+------------------------+
1 row in set (0.00 sec)
-- now MySQL will accept the invalid value, with a warning
mysql> insert into datetimetest(dt) values ('2013-08-26T12:00:00+00:00');
Query OK, 1 row affected, 1 warning (0.00 sec)
mysql> show warnings;
+---------+------+-----------------------------------------+
| Level | Code | Message |
+---------+------+-----------------------------------------+
| Warning | 1265 | Data truncated for column 'dt' at row 1 |
+---------+------+-----------------------------------------+
1 row in set (0.00 sec)
-- the value did get inserted, but the time zone information was lost:
mysql> select * from datetimetest;
+----+---------------------+
| id | dt |
+----+---------------------+
| 1 | 2013-08-26 12:00:00 |
+----+---------------------+
1 row in set (0.00 sec)