MySql配置项explicit_defaults_for_timestamp

如果没有这个配置项,create table时指定timestamp类型的列,会生产默认情况。如下:

root@localhost|test>create table t(id int, c1 timestamp, c2 timestamp, c3 timestamp);
Query OK, 0 rows affected (0.02 sec)

root@localhost|test>show create table t;
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                                                                                                           |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t     | CREATE TABLE `t` (
  `id` int(11) DEFAULT NULL,
  `c1` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `c2` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `c3` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00'
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

而且启动的时候,在错误日志中warning信息:

2015-11-27 15:32:02 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

在my.conf文件中添加配置项,重启。

[mysqld]
basedir=/usr/local/mysql
datadir=/usr/local/mysql/data
explicit_defaults_for_timestamp=true

再建表时:

root@localhost|test>create table t2(id int, c1 timestamp, c2 timestamp, c3 timestamp);
Query OK, 0 rows affected (0.02 sec)

root@localhost|test>show create table t2;
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Table | Create Table                                                                                                                                                                                     |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| t2    | CREATE TABLE `t2` (
  `id` int(11) DEFAULT NULL,
  `c1` timestamp NULL DEFAULT NULL,
  `c2` timestamp NULL DEFAULT NULL,
  `c3` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 |
+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)


你可能感兴趣的:(MySql配置项explicit_defaults_for_timestamp)