安装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
OKFilling 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
OKTo start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your systemPLEASE 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_installationwhich 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.plcd mysql-test ; perl mysql-test-run.plPlease report any problems at http://bugs.mysql.com/The latest information about MySQL is available on the web athttp://www.mysql.comSupport MySQL by buying support/licenses at http://shop.mysql.comNew 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 settingsWARNING: 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.williamsang.com/archives/818.html)

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

转载于:https://www.cnblogs.com/digdeep/p/4727715.html

MySQL 5.6 中的 TIMESTAMP 和 explicit_defaults_for_timestamp 参数相关推荐

  1. mysql show timestamp_MySQL中有关TIMESTAMP和DATETIME的总结

    一.MySQL中如何表示当前时间? 其实,表达方式还是蛮多的,汇总如下: CURRENT_TIMESTAMP CURRENT_TIMESTAMP() NOW() LOCALTIME LOCALTIME ...

  2. MySQL 5.7 中TIMESTAMP with implicit DEFAULT value is deprecated错误

    MySQL 5.7 中TIMESTAMP with implicit DEFAULT value is deprecated错误 解决方案: 打开my.ini(可用记事本打开),找到"[my ...

  3. MySQL中有关TIMESTAMP和DATETIME的总结

    一.MySQL中如何表示当前时间? 其实,表达方式还是蛮多的,汇总如下: CURRENT_TIMESTAMP CURRENT_TIMESTAMP() NOW() LOCALTIME LOCALTIME ...

  4. mysql show timestamp_mysql中 datatime与timestamp的区别说明

    mysql中有三种日期类型: date(年-月-日) create table test(hiredate date); datetime(日期时间类型) create table test(hire ...

  5. mysql的timestamp类型_MySQL数据库中的timestamp类型与时区

    MySQL的timestamp类型时间范围between '1970-01-01 00:00:01' and '2038-01-19 03:14:07',超出这个范围则值记录为'0000-00-00  ...

  6. mysql数据库时间突然是12小时制_为什么存入mysql数据库中的timestamp,晚了13或14个小时...

    # 为什么存入mysql数据库中的timestamp,晚了13个小时 ## 查看数据库时区 ``` show variables like '%time_zone%'; select @@global ...

  7. mysql时间戳13小时_为什么存入mysql数据库中的timestamp,晚了13或14个小时

    为什么存入mysql数据库中的timestamp,晚了13或14个小时 使用markdown,方便大家浏览,就又更新了一下 查看数据库时区 show variables like '%time_zon ...

  8. 深入探讨JDBC往MySQL中插入Timestamp类型字段报错问题

    背景描述 最近处于工作需要,用到了Apache的commons dbutils包来操作数据库.在保存数据到MySQL数据库时,报了一个空指针异常,作为开发多年的Java老鸟,最不怕的就是空指针异常,于 ...

  9. mysql --explicit_【MySQL】 explicit_defaults_for_timestamp 参数解析

    当该参数默认设置为OFF时,其行为如下: 在默认情况下,如果timestamp列没有显式的指明null属性,那么该列会被自动加上not null属性(而其他类型的列如果没有被显式的指定not null ...

最新文章

  1. 【组队学习】【32期】吃瓜教程——西瓜书+南瓜书
  2. nginx实现web负载均衡
  3. 柱状折线图2-双柱状重合堆积折线-重写图例点击事件
  4. SwipeRefreshLayout实现上拉加载
  5. RedHat 系列 Linux 安装后,建立嵌入式开发环境
  6. 【OpenCV笔记】图像预处理
  7. 学生开始学术生涯的好方法
  8. 如何在线创建索引或者重构索引
  9. 华为鸿蒙系统明年8月份,华为鸿蒙系统明年上线,力争第五大操作系统,能否成功?...
  10. Java密码学原型算法实现——第三部分:双线性对
  11. 来拥抱星辰大海吧!中国风云气象卫星系列数字藏品荣耀首发
  12. 微信小程序开发笔记——开发者工具介绍
  13. ubuntu16.04查看opencv版本
  14. 《暗时间(第2版)——思维改变生活》全书网址链接汇总
  15. windows下安装redis并设置开机自启动
  16. linux设备模型七(device_driver细节)
  17. git 本地被覆盖如何恢复
  18. server 08 做DNS和域分离
  19. UEFI开发探索94 – 迷宫小游戏
  20. CVPR 2018 论文解读集锦

热门文章

  1. Android 监听ScrollView的滑动
  2. 巧妙异或思路解子集问题,面试官叫绝
  3. 大型网站架构模式之二
  4. redis的flushall命令
  5. svn: E200009
  6. STM32中GPIO的8种模式
  7. 6.STM32外设函数分类
  8. spring三: 装配bean( 在xml中进行显式配置, 在java中进行显式配置)
  9. 抓包工具Charles基本用法
  10. 大公司的前端开发地址