mysql 5.5 5.6差异,mysql 5.5.46和5.6.28中datetime类型的区别

在mysql 5.5.46中有表,在5.6.28中有相同的表.我在mysql 5.5.46上备份数据库,然后在5.6.28上还原它.因此,两台服务器上的表具有相同的结构和相同的数据.

CREATE TABLE `test` (

`ID` int(11) NOT NULL AUTO_INCREMENT,

`Path` varchar(250) NOT NULL,

`Link` varchar(250) NOT NULL,

`Company` varchar(250) NOT NULL,

`Width` int(11) NOT NULL,

`Height` int(11) NOT NULL,

`View_Count` int(11) NOT NULL DEFAULT '0',

`create_date` datetime NOT NULL,

PRIMARY KEY (`ID`)

) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=utf8

有这样的查询:

insert into test(path,link,company,width,height,view_count)

values('test','test','test',10,10,10)

在mysql 5.5.46上,此查询成功执行,并且create_date值为’0000-00-00 00:00:00′

在mysql 5.6.28上有一个错误字段’Create_Date’没有默认值,并且在逻辑上是因为create_date不为null,所以它没有任何默认值.但是它如何在5.5.46上工作?

解决方法:

根据您提供给我们的信息,您似乎在非严格模式下运行MySQL 5.5.46,但在严格模式下运行MySQL 5.6.28.从MySQL documentation开始:

TIMESTAMP columns declared as NOT NULL and without an explicit DEFAULT clause are treated as having no default value. For inserted rows that specify no explicit value for such a column, the result depends on the SQL mode. If strict SQL mode is enabled, an error occurs. If strict SQL mode is not enabled, the column is assigned the implicit default of ‘0000-00-00 00:00:00’ and a warning occurs. This is similar to how MySQL treats other temporal types such as DATETIME.

您的create_date列的类型为DATETIME,似乎您正在尝试以严格模式在5.6.28数据库中执行INSERT,因此出现错误.

标签:datetime,sql,mysql

来源: https://codeday.me/bug/20191119/2035079.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值