java服务调用mysql报错

2023-12-13 22:00:47

一、前言

前端服务调用后端服务时出现以下报错,原因是使用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

文章来源:https://blog.csdn.net/ApexPredator/article/details/134908137
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。