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

MySQL5.6中的TIMESTAMP和explicit_defaults_for_timestamp参数_MySQL

这篇文章主要介绍了MySQL5.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 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′,且没有警告。
要关闭警告,需要加入下面的参数:

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.bitsCN.com/article/71107.htm)

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

推荐阅读
  • PHP组合工具以及开发所需的工具
    本文介绍了PHP开发中常用的组合工具和开发所需的工具。对于数据分析软件,包括Excel、hihidata、SPSS、SAS、MARLAB、Eview以及各种BI与报表工具等。同时还介绍了PHP开发所需的PHP MySQL Apache集成环境,包括推荐的AppServ等版本。 ... [详细]
  • 本文介绍了在CentOS上安装Python2.7.2的详细步骤,包括下载、解压、编译和安装等操作。同时提供了一些注意事项,以及测试安装是否成功的方法。 ... [详细]
  • 本文介绍了在开发Android新闻App时,搭建本地服务器的步骤。通过使用XAMPP软件,可以一键式搭建起开发环境,包括Apache、MySQL、PHP、PERL。在本地服务器上新建数据库和表,并设置相应的属性。最后,给出了创建new表的SQL语句。这个教程适合初学者参考。 ... [详细]
  • 腾讯安全平台部招聘安全工程师和数据分析工程师
    腾讯安全平台部正在招聘安全工程师和数据分析工程师。安全工程师负责安全问题和安全事件的跟踪和分析,提供安全测试技术支持;数据分析工程师负责安全产品相关系统数据统计和分析挖掘,通过用户行为数据建模为业务决策提供参考。招聘要求包括熟悉渗透测试和常见安全工具原理,精通Web漏洞,熟练使用多门编程语言等。有相关工作经验和在安全站点发表作品的候选人优先考虑。 ... [详细]
  • 推荐一个ASP的内容管理框架(ASP Nuke)的优势和适用场景
    本文推荐了一个ASP的内容管理框架ASP Nuke,并介绍了其主要功能和特点。ASP Nuke支持文章新闻管理、投票、论坛等主要内容,并可以自定义模块。最新版本为0.8,虽然目前仍处于Alpha状态,但作者表示会继续更新完善。文章还分析了使用ASP的原因,包括ASP相对较小、易于部署和较简单等优势,适用于建立门户、网站的组织和小公司等场景。 ... [详细]
  • 本文介绍了如何使用php限制数据库插入的条数并显示每次插入数据库之间的数据数目,以及避免重复提交的方法。同时还介绍了如何限制某一个数据库用户的并发连接数,以及设置数据库的连接数和连接超时时间的方法。最后提供了一些关于浏览器在线用户数和数据库连接数量比例的参考值。 ... [详细]
  • 在说Hibernate映射前,我们先来了解下对象关系映射ORM。ORM的实现思想就是将关系数据库中表的数据映射成对象,以对象的形式展现。这样开发人员就可以把对数据库的操作转化为对 ... [详细]
  • 本文介绍了Oracle数据库中tnsnames.ora文件的作用和配置方法。tnsnames.ora文件在数据库启动过程中会被读取,用于解析LOCAL_LISTENER,并且与侦听无关。文章还提供了配置LOCAL_LISTENER和1522端口的示例,并展示了listener.ora文件的内容。 ... [详细]
  • 本文介绍了在Linux下安装Perl的步骤,并提供了一个简单的Perl程序示例。同时,还展示了运行该程序的结果。 ... [详细]
  • 本文介绍了在Mac上搭建php环境后无法使用localhost连接mysql的问题,并通过将localhost替换为127.0.0.1或本机IP解决了该问题。文章解释了localhost和127.0.0.1的区别,指出了使用socket方式连接导致连接失败的原因。此外,还提供了相关链接供读者深入了解。 ... [详细]
  • 本文介绍了通过mysql命令查看mysql的安装路径的方法,提供了相应的sql语句,并希望对读者有参考价值。 ... [详细]
  • 本文讨论了在数据库打开和关闭状态下,重新命名或移动数据文件和日志文件的情况。针对性能和维护原因,需要将数据库文件移动到不同的磁盘上或重新分配到新的磁盘上的情况,以及在操作系统级别移动或重命名数据文件但未在数据库层进行重命名导致报错的情况。通过三个方面进行讨论。 ... [详细]
  • mysql-cluster集群sql节点高可用keepalived的故障处理过程
    本文描述了mysql-cluster集群sql节点高可用keepalived的故障处理过程,包括故障发生时间、故障描述、故障分析等内容。根据keepalived的日志分析,发现bogus VRRP packet received on eth0 !!!等错误信息,进而导致vip地址失效,使得mysql-cluster的api无法访问。针对这个问题,本文提供了相应的解决方案。 ... [详细]
  • 众筹商城与传统商城的区别及php众筹网站的程序源码
    本文介绍了众筹商城与传统商城的区别,包括所售产品和玩法不同以及运营方式不同。同时还提到了php众筹网站的程序源码和方维众筹的安装和环境问题。 ... [详细]
  • ubuntu用sqoop将数据从hive导入mysql时,命令: ... [详细]
author-avatar
cecillalurw_689
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有