当前位置:Gxlcms > 数据库问题 > docker mysql8.0.17异常Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated colum

docker mysql8.0.17异常Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated colum

时间:2021-07-01 10:21:17 帮助过:13人阅读

https://blog.csdn.net/weixin_42409107/article/details/100074210

Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘x.xxx‘ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

原因是: 

MySQL 5.7.5及以上实现了对功能依赖的检测。如果启用了only_full_group_by SQL模式(在默认情况下是这样),那么MySQL就会拒绝选择列表、条件或顺序列表引用的查询,这些查询将引用组中未命名的非聚合列,而不是在功能上依赖于它们。(在5.7.5之前,MySQL没有检测到功能依赖项,only_full_group_by在默认情况下是不启用的。关于前5.7.5行为的描述,请参阅MySQL 5.6参考手册。)

执行以下个命令,可以查看 sql_mode 的内容。

mysql> SHOW SESSION VARIABLES;

mysql> SHOW GLOBAL VARIABLES;

可见session和global 的sql_mode的值都为:

ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

(如果只有其中一个有此内容的话,下面只需要修改有的那个,亲测可行)

解决方式:执行以下sql

set global sql_mode=‘STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION‘;

set session sql_mode=‘STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION‘;

最后这一步至关重要,好多教程中都没有写,上面是能解决问题,但是当你的mysql重启后,问题就又恢复了。

打开你的my.ini文件在[mysqld] 如果目录下,不存在看看 my.cnf下面,如果做了挂载则在挂载的配置文件加上:sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

重启mysql容器

记住 位置一定不能错!!!要不然不生效

docker mysql8.0.17异常Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated colum

标签:UNC   tables   href   error   条件   end   恢复   一个   _for   

人气教程排行