create table test3(
star varchar(20) not null default '',
birth date not null default '0000-00-00'
)engine myisam charset utf8;
错误:
ERROR 1067 (42000): Invalid default value for ‘birth’
原因:
原文
是因为sql_mode中的NO_ZEROR_DATE导制的,在strict mode中不允许’0000-00-00’作为合法日期
使用下面的命令查看sql_mode
mysql>show variables like ‘sql_mode’;
±--------------±------------------------------------------------------------------------------------------------------------------------------------------+
| Variable_name | Value |
±--------------±------------------------------------------------------------------------------------------------------------------------------------------+
| sql_mode | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
±--------------±------------------------------------------------------------------------------------------------------------------------------------------+
将上面的NO_ZERO_DATE改为下面的 ALLOW_INVALID_DATES
mysql> set sql_mode=‘ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,ALLOW_INVALID_DATES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION’;
上面的设置是临时设置,在重新登陆后,该设置又恢复为NO_ZERO_DATE
永久修改办法:
修改my.cnf文件,在[mysqld]中添加
sql-mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
重启mysql
作者:蓝星花
来源:CSDN
原文:https://blog.csdn.net/m0_37499059/article/details/79186829
版权声明:本文为博主原创文章,转载请附上博文链接!
删除线格式
stackoverflow
Simply, before you run any statements put this in the first line:
SET sql_mode = '';
shareimprove this answer