Caused by: java.sql.SQLException: Expression #1 of ORDER BY clause is not in SELECT list, references column 'blemon_business.attachdise1_.order_index' which is not in SELECT list; this is incompatible with DISTINCT2021/7/12 上午9:31:20 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:129) ~[mysql-connector-java-8.0.20.jar!/:8.0.20]2021/7/12 上午9:31:20 at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) ~[mysql-connector-java-8.0.20.jar!/:8.0.20]2021/7/12 上午9:31:20 at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) ~[mysql-connector-java-8.0.20.jar!/:8.0.20]2021/7/12 上午9:31:20 at com.mysql.cj.jdbc.ClientPreparedStatement.executeInternal(ClientPreparedStatement.java:953) ~[mysql-connector-java-8.0.20.jar!/:8.0.20]2021/7/12 上午9:31:20 at com.mysql.cj.jdbc.ClientPreparedStatement.executeQuery(ClientPreparedStatement.java:1003) ~[mysql-connector-java-8.0.20.jar!/:8.0.20]2021/7/12 上午9:31:20 at com.alibaba.druid.pool.DruidPooledPreparedStatement.executeQuery(DruidPooledPreparedStatement.java:228) ~[druid-1.1.12.jar!/:1.1.12]2021/7/12 上午9:31:20 at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:57) ~[hibernate-core-5.4.15.Final.jar!/:5.4.15.Final]2021/7/12 上午9:31:20 ... 156 common frames omitted
该错误是由于SQL_Model包含了ONLY_FULL_GROUP_BY模式引起
查看SQL_Model
select @@global.sql_mode
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
直接set修改
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 '
然而数据库重启后又出现了,因此修改配置文件
mysql --help|grep 'my.cnf'
由于mysql不是作为服务起的,因此需要查找下mysqld
which mysqld
查找配置文件位置
mysqld --verbose --help |grep -A 1 'Default options'
查看配置文件,发现引用到了另外一个文件上面
编辑正在引用的文件后重启
vim /etc/mysql/conf.d/mysql.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
重启