MySQL 5.6 中TIMESTAMP with implicit DEFAULT value is deprecated错误

安装MySQL时,有warning:

[root@localhost mysql]# scripts/mysql_install_db --user=mysql
Installing MySQL system tables...2015-08-13 14:20:09 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-08-13 14:20:09 0 [Note] ./bin/mysqld (mysqld 5.6.26) starting as process 1934 ...
2015-08-13 14:20:09 1934 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2015-08-13 14:20:09 1934 [Note] InnoDB: The InnoDB memory heap is disabled
2015-08-13 14:20:09 1934 [Note] InnoDB: Mutexes and rw_locks use InnoDB's own implementation
2015-08-13 14:20:09 1934 [Note] InnoDB: Memory barrier is not used
2015-08-13 14:20:09 1934 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-08-13 14:20:09 1934 [Note] InnoDB: Using Linux native AIO
2015-08-13 14:20:09 1934 [Note] InnoDB: Not using CPU crc32 instructions
2015-08-13 14:20:09 1934 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-08-13 14:20:09 1934 [Note] InnoDB: Completed initialization of buffer pool
2015-08-13 14:20:10 1934 [Note] InnoDB: The first specified data file ./ibdata1 did not exist: a new database to be created!
2015-08-13 14:20:10 1934 [Note] InnoDB: Setting file ./ibdata1 size to 12 MB
2015-08-13 14:20:10 1934 [Note] InnoDB: Database physically writes the file full: wait...
2015-08-13 14:20:10 1934 [Note] InnoDB: Setting log file ./ib_logfile101 size to 48 MB
2015-08-13 14:20:11 1934 [Note] InnoDB: Setting log file ./ib_logfile1 size to 48 MB
2015-08-13 14:20:12 1934 [Note] InnoDB: Renaming log file ./ib_logfile101 to ./ib_logfile0
2015-08-13 14:20:12 1934 [Warning] InnoDB: New log files created, LSN=45781
2015-08-13 14:20:12 1934 [Note] InnoDB: Doublewrite buffer not found: creating new
2015-08-13 14:20:12 1934 [Note] InnoDB: Doublewrite buffer created
2015-08-13 14:20:12 1934 [Note] InnoDB: 128 rollback segment(s) are active.
2015-08-13 14:20:12 1934 [Warning] InnoDB: Creating foreign key constraint system tables.
2015-08-13 14:20:12 1934 [Note] InnoDB: Foreign key constraint system tables created
2015-08-13 14:20:12 1934 [Note] InnoDB: Creating tablespace and datafile system tables.
2015-08-13 14:20:12 1934 [Note] InnoDB: Tablespace and datafile system tables created.
2015-08-13 14:20:12 1934 [Note] InnoDB: Waiting for purge to start
2015-08-13 14:20:12 1934 [Note] InnoDB: 5.6.26 started; log sequence number 0
2015-08-13 14:20:14 1934 [Note] Binlog end
2015-08-13 14:20:14 1934 [Note] InnoDB: FTS optimize thread exiting.
2015-08-13 14:20:14 1934 [Note] InnoDB: Starting shutdown...
2015-08-13 14:20:16 1934 [Note] InnoDB: Shutdown completed; log sequence number 1625977
OK

Filling help tables...2015-08-13 14:20:16 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated.
Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2015-08-13 14:20:16 0 [Note] ./bin/mysqld (mysqld 5.6.26) starting as process 1957 ...
2015-08-13 14:20:16 1957 [Note] InnoDB: Using mutexes to ref count buffer pool pages
2015-08-13 14:20:16 1957 [Note] InnoDB: The InnoDB memory heap is disabled
2015-08-13 14:20:16 1957 [Note] InnoDB: Mutexes and rw_locks use InnoDB's own implementation
2015-08-13 14:20:16 1957 [Note] InnoDB: Memory barrier is not used
2015-08-13 14:20:16 1957 [Note] InnoDB: Compressed tables use zlib 1.2.3
2015-08-13 14:20:16 1957 [Note] InnoDB: Using Linux native AIO
2015-08-13 14:20:16 1957 [Note] InnoDB: Not using CPU crc32 instructions
2015-08-13 14:20:16 1957 [Note] InnoDB: Initializing buffer pool, size = 128.0M
2015-08-13 14:20:16 1957 [Note] InnoDB: Completed initialization of buffer pool
2015-08-13 14:20:16 1957 [Note] InnoDB: Highest supported file format is Barracuda.
2015-08-13 14:20:16 1957 [Note] InnoDB: 128 rollback segment(s) are active.
2015-08-13 14:20:16 1957 [Note] InnoDB: Waiting for purge to start
2015-08-13 14:20:16 1957 [Note] InnoDB: 5.6.26 started; log sequence number 1625977
2015-08-13 14:20:17 1957 [Note] Binlog end
2015-08-13 14:20:17 1957 [Note] InnoDB: FTS optimize thread exiting.
2015-08-13 14:20:17 1957 [Note] InnoDB: Starting shutdown...
2015-08-13 14:20:18 1957 [Note] InnoDB: Shutdown completed; log sequence number 1625987
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

 ./bin/mysqladmin -u root password 'new-password'
 ./bin/mysqladmin -u root -h localhost.localdomain password 'new-password'

Alternatively you can run:

 ./bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default. This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:

 cd . ; ./bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl

 cd mysql-test ; perl mysql-test-run.pl

Please report any problems at http://bugs.mysql.com/

The latest information about MySQL is available on the web at

 http://www.mysql.com

Support MySQL by buying support/licenses at http://shop.mysql.com

New default config file was created as ./my.cnf and
will be used by default by the server when you start it.
You may edit this file to change server settings

WARNING: Default config file /etc/my.cnf exists on the system
This file will be read by default by the MySQL server
If you do not want to use this, either remove it, or use the
--defaults-file argument to mysqld_safe when starting the server

[root@localhost mysql]#

[Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).

其原因是从 5.6开始,timestamp 的默认行为已经是 deprecated 了。

在MySQL 5.6.6之前,TIMESTAMP的默认行为:

•TIMESTAMP列如果没有明确声明NULL属性,默认为NOT NULL。(而其他数据类型,如果没有显示声明为NOT NULL,则允许NULL值。)设置TIMESTAMP的列值为NULL,会自动存储为当前timestamp。
•表中的第一个TIMESTAMP列,如果没有声明NULL属性、DEFAULT或者 ON UPDATE,会自动分配 DEFAULT CURRENT_TIMESTAMP和ON UPDATE CURRENT_TIMESTAMP 属性。
•表中第二个TIMESTAMP列,如果没有声明为NULL或者DEFAULT子句,默认自动分配'0000-00-00 00:00:00′。插入行时没有指明改列的值,该列默认分配'0000-00-00 00:00:00′,且没有警告。

要关闭警告,需要加入下面的参数:

[mysqld]
explicit_defaults_for_timestamp=true

重启MySQL后错误消失,这时TIMESTAMP的行为如下:

•TIMESTAMP如果没有显示声明NOT NULL,是允许NULL值的,可以直接设置改列为NULL,而没有默认填充行为。
•TIMESTAMP不会默认分配DEFAULT CURRENT_TIMESTAMP 和 ON UPDATE CURRENT_TIMESTAMP属性。
•声明为NOT NULL且没有默认子句的TIMESTAMP列是没有默认值的。往数据表中插入列,又没有给TIMESTAMP列赋值时,如果是严格SQL模式,会抛出一 个错误,如果严格SQL模式没有启用,该列会赋值为'0000-00-00 00:00:00′,同时出现一个警告。(这和MySQL处理其他时间类型数据一样,如DATETIME)
(参见:http://www.jb51.net/article/71054.htm)

也就是 explicit_defaults_for_timestamp 关闭了 timestamp 类型字段锁拥有的一些会让人感到奇怪的默认行为,加入了该参数之后,如果还需要为 timestamp类型的字段指定默认行为,那么就需要显示的在创建表时显示的指定。explicit_defaults_for_timestamp 也就是这个意思:显示指定默认值为timestamp类型的字段。

(0)

相关推荐

  • mysql 数据类型TIMESTAMP

    在mysql中timestamp数据类型是一个比较特殊的数据类型,他可以自动在你不使用程序更新情况下只要你更新了记录timestamp会自动更新时间 通常表中会有一个Create date 创建日期的字段,其它数据库均有默认值的选项.MySQL也有默认值timestamp,但在MySQL中,不仅是插入就算是修改也会更新timestamp的值! 这样一来,就不是创建日期了,当作更新日期来使用比较好! 因此在MySQL中要记录创建日期还得使用datetime 然后使用NOW() 函数完成! 1: 如

  • MySQL timestamp的类型与时区实例详解

     MySQL timestamp的类型与时区 MySQL的timestamp类型时间范围between '1970-01-01 00:00:01' and '2038-01-19 03:14:07',超出这个范围则值记录为'0000-00-00 00:00:00',该类型的一个重要特点就是保存的时间与时区密切相关,上述所说的时间范围是UTC(Universal Time Coordinated)标准,指的是经度0度上的标准时间,我国日常生活中时区以首都北京所处的东半球第8区为基准,统一使用东8区

  • mysql From_unixtime及UNIX_TIMESTAMP及DATE_FORMAT日期函数

    from_unixtime()是MySQL里的时间函数 date为需要处理的参数(该参数是Unix 时间戳),可以是字段名,也可以直接是Unix 时间戳字符串 后面的 '%Y%m%d' 主要是将返回值格式化 例如: mysql>SELECT FROM_UNIXTIME( 1249488000, '%Y%m%d' ) ->20071120 mysql>SELECT FROM_UNIXTIME( 1249488000, '%Y年%m月%d' ) ->2007年11月20 UNIX_TI

  • MySQL 5.6 中的 TIMESTAMP 和 explicit_defaults_for_timestamp 参数

    安装MySQL时,有warning: [root@localhost mysql]# scripts/mysql_install_db --user=mysql Installing MySQL system tables...2015-08-13 14:20:09 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server

  • mysql之TIMESTAMP(时间戳)用法详解

    一.TIMESTAMP的变体 TIMESTAMP时间戳在创建的时候可以有多重不同的特性,如: 1.在创建新记录和修改现有记录的时候都对这个数据列刷新: TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP 2.在创建新记录的时候把这个字段设置为当前时间,但以后修改时,不再刷新它: TIMESTAMP DEFAULT CURRENT_TIMESTAMP 3.在创建新记录的时候把这个字段设置为0,以后修改时刷新它: TIMES

  • MySQL timestamp自动更新时间分享

    通常表中会有一个Create date 创建日期的字段,其它数据库均有默认值的选项.MySQL也有默认值timestamp,但在MySQL中,不仅是插入就算是修改也会更新timestamp的值! 这样一来,就不是创建日期了,当作更新日期来使用比较好! 因此在MySQL中要记录创建日期还得使用datetime 然后使用NOW() 函数完成! 1,TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP  在创建新记录和修改现有记

  • MySQL 5.6 中 TIMESTAMP 的变化分析

    在MySQL 5.6.6之前,TIMESTAMP的默认行为: ■TIMESTAMP列如果没有明确声明NULL属性,默认为NOT NULL.(而其他数据类型,如果没有显示声明为NOT NULL,则允许NULL值.)设置TIMESTAMP的列值为NULL,会自动存储为当前timestamp. ■表中的第一个TIMESTAMP列,如果没有声明NULL属性.DEFAULT或者 ON UPDATE,会自动分配 DEFAULT CURRENT_TIMESTAMP和ON UPDATE CURRENT_TIME

  • 解析mysql中UNIX_TIMESTAMP()函数与php中time()函数的区别

    mysql 中:UNIX_TIMESTAMP(), UNIX_TIMESTAMP(date)若无参数调用,则返回一个Unix timestamp ('1970-01-01 00:00:00' GMT 之后的秒数) 作为无符号整数.若用date 来调用UNIX_TIMESTAMP(),它会将参数值以'1970-01-01 00:00:00' GMT后的秒数的形式返回.date 可以是一个DATE 字符串.一个 DATETIME字符串.一个 TIMESTAMP或一个当地时间的YYMMDD 或YYYM

  • Mysql中的Datetime和Timestamp比较

    mysql中用于表示时间的三种类型date, datetime, timestamp (如果算上int的话,四种) 比较容易混淆,下面就比较一下这三种类型的异同 相同点 都可以用于表示时间 都呈字符串显示 不同点 1.顾名思义,date只表示'YYYY-MM-DD'形式的日期,datetime表示'YYYY-MM-DD HH:mm:ss'形式的日期加时间,timestamp与datetime显示形式一样. 2.date和datetime可表示的时间范围为'1000-01-01'到'9999-12

  • MySQL错误TIMESTAMP column with CURRENT_TIMESTAMP的解决方法

    在部署程序时遇到的一个问题,MySQL定义举例如下: 复制代码 代码如下: CREATE TABLE `example` (  `id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,  `created` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,  `lastUpdated` TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP,  PRIMARY KEY (`id`)

  • MySQL 5.6 中 TIMESTAMP有那些变化

    在MySQL 5.6.6之前,TIMESTAMP的默认行为: TIMESTAMP列如果没有明确声明NULL属性,默认为NOT NULL.(而其他数据类型,如果没有显示声明为NOT NULL,则允许NULL值.)设置TIMESTAMP的列值为NULL,会自动存储为当前timestamp. 表中的第一个TIMESTAMP列,如果没有声明NULL属性.DEFAULT或者 ON UPDATE,会自动分配 DEFAULT CURRENT_TIMESTAMP和ON UPDATE CURRENT_TIMEST

  • mysql多个TimeStamp设置的方法解读

    timestamp设置默认值是Default CURRENT_TIMESTAMP timestamp设置随着表变化而自动更新是ON UPDATE CURRENT_TIMESTAMP 但是由于 一个表中至多只能有一个字段设置CURRENT_TIMESTAMP 两行设置DEFAULT CURRENT_TIMESTAMP是不行的. 还有一点要注意 复制代码 代码如下: CREATE TABLE `device` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREME

随机推荐