Caused by: java.sql.SQLSyntaxErrorException: Expression #6 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'hospital.he.equipment_name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:955) at com.mysql.cj.jdbc.ClientPreparedStatement.execute(ClientPreparedStatement.java:372) at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3005) at com.alibaba.druid.filter.FilterAdapter.preparedStatement_execute(FilterAdapter.java:1058) at com.alibaba.druid.filter.FilterChainImpl.preparedStatement_execute(FilterChainImpl.java:3003) at com.alibaba.druid.proxy.jdbc.PreparedStatementProxyImpl.execute(PreparedStatementProxyImpl.java:136) at com.alibaba.druid.pool.DruidPooledPreparedStatement.execute(DruidPooledPreparedStatement.java:493)
项目某项数据查询之后不显示详细列表,查看服务器日志之后8月6日有 this is incompatible with sql_mode=only_full_group_by的报错, 百度了一番之后,发现这个问题是发生在mysql 5.7.5 版本及以上版本 .mysql 5.7.5版本以上默认的sql配置是是:sql_mode=“ONLY_FULL_GROUP_BY”,这个配置严格执行了"SQL92标准"。很多从5.6升级到5.7时,为了语法兼容,大部分都会选择调整sql_mode,使其保持跟5.6一致,为了尽量兼容程序。
在sql执行时,由于开启了ONLY_FULL_GROUP_BY的设置,如果select 的字段不在 group by 中,并且select 的字段未使用聚合函数(SUM,AVG,MAX,MIN等)的话,那么这条sql查询是被mysql认为非法的,会报错误.
直接通过修改配置文件永久修改sql_mode
1)进入服务器,编辑my.cnf
文件地址一般在/etc/my.cnf,/etc/mysql/my.cnf
使用vim my.cnf命令编辑my.cnf,进入my.cnf后,按 i 键进入编辑
找到sql-mode的位置,去掉ONLY_FULL_GROUP_BY,然后重启MySQL;
有的my.cnf中没有sql_mode,需要进行追加
sql-mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
注意要加入到[mysqld]下面,如加入到其他地方,重启后也不生效
# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysqld] character_set_server=utf8 init_connect='SET NAMES utf8' port=3308 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)修改好之后重启MySQL服务
我遇到的这次问题就这样解决了.



