Mysql sql_mode=only_full_group_by

Posted by JJput on 07-05,2022

临时方法

mysql重启后会重置
修改后需要重新连接才会生效

Mysql 8.0

在Navicat中或者通过命令行进入数据库执行下面命令:

set sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

Mysql 5.7

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';
 
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';

永久方法

通过修改mysql.cnf并添加以下配置

#mysql8.0
[mysqld]
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'

#mysql5.7
[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'

docker的话可以将其文件复制出来再复制进去

docker cp mysql5_7:/etc/mysql/mysql.cnf  /Users/junj/Desktop/
docker cp /Users/junj/Desktop/mysql.cnf mysql5_7:/etc/mysql/