mysql5.7版本的sql_mode=only_full_group_by问题

从mysql5.7以下版本走过来的大部分人对这个group by  不习惯5.7的only_full_group_by,也就是展示的列都需要group by。今天在换个数据库跑应用的时候报错了,如下日志:

Caused by: java.sql.SQLSyntaxErrorException: Expression #24 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'trial.ct.case_type_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:536) ~[mysql-connector-java-6.0.6.jar!/:6.0.6]
	at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:513) ~[mysql-connector-java-6.0.6.jar!/:6.0.6]

操作如下:

进入路径:/etc/mysql/mysql.conf.d/mysqld.cnf,

在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

 

mysql5.7版本的sql_mode=only_full_group_by问题_第1张图片

重启mysql服务即可:

service mysql restart

你可能感兴趣的:(mysql)