热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

MySQL5.6中TIMESTAMPwithimplicitDEFAULTvalueisdeprecated错误

安装mysql的时候出现TIMESTAMPwithimplicitDEFAULTvalueisdeprecated.Pleaseuse--explicit_defaults_for_timestampserveroption(seedocumentationformoredetails),可以参考下面的方法解决

安装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)
(参见:https://www.jb51.net/article/71054.htm)

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


推荐阅读
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 安装mysqlclient失败解决办法
    本文介绍了在MAC系统中,使用django使用mysql数据库报错的解决办法。通过源码安装mysqlclient或将mysql_config添加到系统环境变量中,可以解决安装mysqlclient失败的问题。同时,还介绍了查看mysql安装路径和使配置文件生效的方法。 ... [详细]
  • 本文介绍了在CentOS上安装Python2.7.2的详细步骤,包括下载、解压、编译和安装等操作。同时提供了一些注意事项,以及测试安装是否成功的方法。 ... [详细]
  • 腾讯安全平台部招聘安全工程师和数据分析工程师
    腾讯安全平台部正在招聘安全工程师和数据分析工程师。安全工程师负责安全问题和安全事件的跟踪和分析,提供安全测试技术支持;数据分析工程师负责安全产品相关系统数据统计和分析挖掘,通过用户行为数据建模为业务决策提供参考。招聘要求包括熟悉渗透测试和常见安全工具原理,精通Web漏洞,熟练使用多门编程语言等。有相关工作经验和在安全站点发表作品的候选人优先考虑。 ... [详细]
  • 本文介绍了如何在MySQL中将零值替换为先前的非零值的方法,包括使用内联查询和更新查询。同时还提供了选择正确值的方法。 ... [详细]
  • Centos7.6安装Gitlab教程及注意事项
    本文介绍了在Centos7.6系统下安装Gitlab的详细教程,并提供了一些注意事项。教程包括查看系统版本、安装必要的软件包、配置防火墙等步骤。同时,还强调了使用阿里云服务器时的特殊配置需求,以及建议至少4GB的可用RAM来运行GitLab。 ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • 本文介绍了在Linux下安装Perl的步骤,并提供了一个简单的Perl程序示例。同时,还展示了运行该程序的结果。 ... [详细]
  • Webmin远程命令执行漏洞复现及防护方法
    本文介绍了Webmin远程命令执行漏洞CVE-2019-15107的漏洞详情和复现方法,同时提供了防护方法。漏洞存在于Webmin的找回密码页面中,攻击者无需权限即可注入命令并执行任意系统命令。文章还提供了相关参考链接和搭建靶场的步骤。此外,还指出了参考链接中的数据包不准确的问题,并解释了漏洞触发的条件。最后,给出了防护方法以避免受到该漏洞的攻击。 ... [详细]
  • Linux磁盘的分区、格式化的观察和操作步骤
    本文介绍了如何观察Linux磁盘的分区状态,使用lsblk命令列出系统上的所有磁盘列表,并解释了列表中各个字段的含义。同时,还介绍了使用parted命令列出磁盘的分区表类型和分区信息的方法。在进行磁盘分区操作时,根据分区表类型选择使用fdisk或gdisk命令,并提供了具体的分区步骤。通过本文,读者可以了解到Linux磁盘分区和格式化的基本知识和操作步骤。 ... [详细]
  • 如何在服务器主机上实现文件共享的方法和工具
    本文介绍了在服务器主机上实现文件共享的方法和工具,包括Linux主机和Windows主机的文件传输方式,Web运维和FTP/SFTP客户端运维两种方式,以及使用WinSCP工具将文件上传至Linux云服务器的操作方法。此外,还介绍了在迁移过程中需要安装迁移Agent并输入目的端服务器所在华为云的AK/SK,以及主机迁移服务会收集的源端服务器信息。 ... [详细]
  • 本文讨论了在数据库打开和关闭状态下,重新命名或移动数据文件和日志文件的情况。针对性能和维护原因,需要将数据库文件移动到不同的磁盘上或重新分配到新的磁盘上的情况,以及在操作系统级别移动或重命名数据文件但未在数据库层进行重命名导致报错的情况。通过三个方面进行讨论。 ... [详细]
  • imx6ull开发板驱动MT7601U无线网卡的方法和步骤详解
    本文详细介绍了在imx6ull开发板上驱动MT7601U无线网卡的方法和步骤。首先介绍了开发环境和硬件平台,然后说明了MT7601U驱动已经集成在linux内核的linux-4.x.x/drivers/net/wireless/mediatek/mt7601u文件中。接着介绍了移植mt7601u驱动的过程,包括编译内核和配置设备驱动。最后,列举了关键词和相关信息供读者参考。 ... [详细]
  • 欢乐的票圈重构之旅——RecyclerView的头尾布局增加
    项目重构的Git地址:https:github.comrazerdpFriendCircletreemain-dev项目同步更新的文集:http:www.jianshu.comno ... [详细]
  • 本文介绍了pack布局管理器在Perl/Tk中的使用方法及注意事项。通过调用pack()方法,可以控制部件在显示窗口中的位置和大小。同时,本文还提到了在使用pack布局管理器时,应注意将部件分组以便在水平和垂直方向上进行堆放。此外,还介绍了使用Frame部件或Toplevel部件来组织部件在窗口内的方法。最后,本文强调了在使用pack布局管理器时,应避免在中间切换到grid布局管理器,以免造成混乱。 ... [详细]
author-avatar
yo繽紛樂
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有