0
点赞
收藏
分享

微信扫一扫

mysql报错 “Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated“的解决办法


完整报错内容:

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated 
column 'a.logid' which is not functionally dependent on columns in GROUP BY clause; 
this is incompatible with sql_mode=only_full_group_by

如下图所示

mysql报错 “Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated“的解决办法_重启

 提示得也很清楚 使用 GROUP BY 语句和sql模式 only_full_group_by 冲突

原因:

mysql在5.7.5版本之后默认sql模式中包含 ONLY_FULL_GROUP_BY

解决办法:

找到mysql的配置文件,一般在/etc/mysql/mysql.conf.d/mysqld.cnf

如果该文件中有sql_mode配置,则将ONLY_FULL_GROUP_BY去掉。

如果没有,则添加以下内容

[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

添加好后,如下图所示

mysql报错 “Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated“的解决办法_重启_02

 注意:

执行完后要执行命令 ​​service mysql restart ​​重启mysql后才能起效

举报

相关推荐

0 条评论