com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #75 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'xxxxxxx' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
本地数据库报错原因
默认的 MySQL 配置的 sql_mode
配置 only_full_group_by
,需要 GROUP BY
中包含所有在 SELECT中出现的字段。
解决办法
1、服务器(Linux)
在配置文件 my.cnf 中修改 sql_mode
的配置,在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
2、Windows
在sql命令界面输入以下命令(临时生效)
SELECT @@sql_mode;
set @@global.sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
以上方法重启sql服务就会失效,永久生效需要修改my.ini配置文件,在其 my.ini 文件中添加以下配置:
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
重启服务即可生效。