MySQL中group by 异常

Error querying database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘库名.表名.字段名’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

出现异常的原因:

当使用MySQL 5.7+在实例上加载仪表板时,会发生此错误。默认情况下,MySQL 5.7+禁用了在SELECT子句中包含列的能力,这些列也不在GROUPBY子句中。

解决办法:

一、在windows中:

1、找到mysql的my.ini配置文件:
在这里插入图片描述
2、将sql_mode属性中的“ONLY_FULL_GROUP_BY,”去掉,如果配置文件中没有sql_mode属性,MySQL服务器使用的就是默认的,我们在配置文件中加上:sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
在这里插入图片描述

二、在linux中:

vim /etc/my.cnf

在/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

在这里插入图片描述

保存后重启mysql:

service mysqld restart

如有不懂,请添加QQ群:920199935

Guess you like

Origin blog.csdn.net/huo_wa/article/details/117446535