phpsutdy-爱好者 2019-08-07 17:15:291楼
mysql从5.7的某个版本开始调整了默认参数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 1 row in set (0.00 sec)mysql>
其中ONLY_FULL_GROUP_BY就是影响了上面SQL语句是否报异常
解决方法:
1、改写SQL语句,毕竟上面的写法不是标准的SQL语句
2、登陆mysql服务器,执行以下命令,在global与session级都修改
mysql> set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'; mysql> set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
3、结合第2种方法,在my.cnf文件中,指定sql_mode的值:
[mysqld] sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
赞 +添加回复