环境
mysql版本:mysql8.0.29-debain
安装方式:docker
问题复现
通过python,将csv数据插入mysql表中,具体方式以及代码 Python 操作 MySQL 写入读出 CSV 文件
问题出现 1366 Incorrect integer value
问题原因
建表时,id 是 int 类型,但传递的默认值是 空字符串,则导致错误出现
解决方法
Mysql错误1366 解决方法
第二种解决方案:将 my.ini 中的sql-model修改为:sql-mode=“NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION”
, 对于mysql8.0 以后的版本是不可以的, 因为 NO_AUTO_CREATE_USER
已经废弃:
废除说明
The following features related to account management are removed:
- Using GRANT to create users. Instead, use CREATE USER. Following this practice makes the NO_AUTO_CREATE_USER SQL mode immaterial for GRANT statements, so it too is removed.
因此, 我尝试在mysql 挂载出来的文件 /root/mysql/conf
,加上以下字段(即第二种解决方案去掉 NO_AUTO_CREATE_USER
)
# 定义mysql应该支持的sql语法,数据校验
sql_mode = NO_ENGINE_SUBSTITUTION
重启mysql容器发现问题解决