一、前言
前端服务调用后端服务时出现以下报错,原因是使用mysql5.7版本数据库中存在ONLY_FULL_GROUP_BY这个配置项导致的不兼容
MySQLSyntaxErrorException: Expression #32 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'demeter_foundation.sorg.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
二、解决
在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';
8.0以上版本执行
set @@global.sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
更改mysql配置文件(永久更改)
vi /etc/my.cnf
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION #5.7以上版本配置此项
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION #8.0以上版本配置此项
重新启动mysql服务
systemctl restart mysqld