当前位置:   article > 正文

Data truncation: Incorrect datetime value: ‘0000-00-00 00:00:00.000‘ for column ‘createTime‘ at row

data truncation: incorrect datetime value

这是因为sql_mode中有对datetime类型的非0限制

可以查看自己数据库的sql_mode

  1. # 查看当前sql_mode
  2. select @@sql_mode;
  3. # 查看全局sql_mode
  4. select @@global.sql_mode;

myqsl数据库一般查询结果为【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】

然后设置数据库的sql_mode【查询到的sql_mode中的NO_ZERO_DATENO_ZERO_IN_DATE删除】

  1. # 修改全局sql_mode
  2. set @@global.sql_mode = 'STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
  3. # 修改当前sql_mode
  4. set @@sql_mode = 'STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

======================================================================

记录一些常用的SQL

查看MYSQL数据库所占用的内存

  1. SELECT CONCAT(TRUNCATE(SUM(data_length)/1024/1024,2),'MB') AS data_size,
  2. CONCAT(TRUNCATE(SUM(max_data_length)/1024/1024,2),'MB') AS max_data_size,
  3. CONCAT(TRUNCATE(SUM(data_free)/1024/1024,2),'MB') AS data_free,
  4. CONCAT(TRUNCATE(SUM(index_length)/1024/1024,2),'MB') AS index_size
  5. FROM information_schema.tables WHERE TABLE_SCHEMA = 'xxxx';

查看某个数据库中表所占用的内存

  1. select TABLE_NAME,
  2. concat(truncate(data_length/1024/1024,2),'MB') as data_size,
  3. concat(truncate(index_length/1024/1024,2),'MB') as index_size
  4. from information_schema.tables where TABLE_SCHEMA = 'xxxx'
  5. group by TABLE_NAME
  6. order by data_length desc;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/607210
推荐阅读
相关标签
  

闽ICP备14008679号