mysql explicit_defaults_for_timestamp参数
在mysql中: ? ? 1 mysql> create table timestamp_eg( 2 -> id int not null auto_increment, 3 -> time1 timestamp,1)"> 4 -> time2 5 -> time3 timestamp NOT NULL DEFAULT '2010-01-01 00:00:00' 6 -> time4 7 -> primary key(id)); 8 Query OK,0 rows affected (0.01 sec) 9 10 mysqlinsert into timestamp_eg(id) values(1); 11 Query OK,1); font-weight: bold">1 row affected (0.0012 13 mysqlselect * from timestamp_eg; 14 +----+---------------------+---------------------+---------------------+---------------------+ 15 | id | time1 | time2 | time3 | time4 | 16 17 | 1 | 2015-1216 09:23:33 00000000 00:20100101 18 19 1 row in set (20 21 mysqlupdate timestamp_eg set id=2 where id; 22 Query OK,1); font-weight: bold">0.0223 Rows matched: 1 Changed: 1 Warnings: 0 24 25 mysql26 27 28 29 2 25:30 31 32 33 mysqlinto timestamp_eg(id,time4) 3,2011-01-01 00:00:0034 Query OK,1)">35 36 mysql37 38 39 40 41 3 28:04 201142 43 2 rows 44 45 mysql4 346 Query OK,1)">47 Rows matched: 48 49 mysql50 51 52 53 54 4 24 55 56 57 58 mysql> ? ? 从MySQL5.6.6这种默认设置的方法被废弃了。在MySQL启动时会出现以下警告: ? 1 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. 2 Please use explicit_defaults_for_timestamp server option (see 3 documentation for more details). ? 要想取消该警告,在启动mysql时,my.cnf中加入 ? ? mysqld] 2 explicit_defaults_for_timestamp=true ? ? 修改该参数后,timestamp类型的列的处理方式也会发生变化: - timestamp列如果没有显式定义为not null,则支持null属性。设置timestamp的列值为null,就不会被设置为current timestamp ? timestamp_02( -> id -> time1 -> (id) -> ); 6 Query OK,1); font-weight: bold">0.03 7 8 mysqlinto timestamp_02(id) 9 ERROR 1364 (HY000): Field time1' doesnt have a default value 10 mysql> ? ? ? (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |