55

MySQL 8.0.13 设置日期为0000-00-00 00:00:00时出现的问题

 5 years ago
source link: https://studygolang.com/articles/17818?amp%3Butm_medium=referral
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

刚开始学习数据库操作,今天存数据时发现,保存的时候报错 (Error 1292: Incorrect datetime value: '0000-00-00' for column 'deleted_at' at row 1) ,之后就搜索了下原因,是因为 MySQL 存日期时不允许出现这种格式导致的。下面记录下解决问题的经过:

先是根据 Mysql 数据库date, datetime类型设置0000-00-00默认值报错问题 这篇博客操作的。但是发现。我电脑上没有文章中提到的 cnf 文件。于是就在网上搜索该文件。粘贴了 my.cnf 这个内容到 /etc/my.cnf 里边。

可是等我将

sql-mode=ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

粘贴到文件所在位置时,还是不成功。MySQL直接启动不起来。后来在命令行中设置 sql_mode 的时候看到了错误提示:

mysql> SET GLOBAL sql_mode = 'ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
ERROR 1231 (42000): Variable 'sql_mode' can't be set to the value of 'NO_AUTO_CREATE_USER'

ERROR 1231 (42000): Variable 'sql_mode' can't be set to the value of 'NO_AUTO_CREATE_USER'

意思就是不让设置 NO_AUTO_CREATE_USER 呗。那就不设置呀。之后再 my.cnf 文件中的 sql-mode 一行去掉改值就成功了。

MySQL版本:8.0.13

bVbnwiZ?w=2116&h=672


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK