MYSQL:Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column
使用Qt5.11.0运行代码时,在对表进行操作时出该错误,报错为:
Expression #2 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 QMYSQL: Unable to execute query"
错误原因:
MySQL 5.7.5和以上版本实现了对功能依赖的检测。如果启用了only_full_group_by SQL模式(默认情况),那么MySQL会拒绝选择列表、条件或顺序列表引用的查询,这些查询将引用组中未命名的非聚合列,而不是在功能上依赖于它们。(在5.7.5之前,MySQL没有检测到功能依赖项,only_full_group_by在默认情况下不启用)
解决办法:
一、一次解决(mysql重启后会恢复原设置)
1、查看sql_mode内容
select @@global.sql_mode;
查询结果为:
only_full_group_by说明:
only_full_group_by :使用only_full_group_by就是使用和oracle一样的group 规则, select的列都要在group中,或者本身是聚合列(SUM,AVG,MAX,MIN) 才行。
2、去掉ONLY_FULL_GROUP_BY,重新设置模式
set @@global.sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
一些网友为:
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;
根据个人实际情况设置。
二、永久解决
1、查看mysql启动时读取的配置文件目录:
mysql --help|grep 'my.cnf'
2、修改my.cnf配置文件
编辑 /etc/my.cnf 文件:
vim /etc/my.cnf或者
gedit /etc/my.cnf
在文件中查看是否有sql_mode的内容,如果有,去掉only_full_group_by,如果没有,则加入以下配置语句,保存并退出。
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
注意!!!!!!!!!!!!!
在修改配置文件之前,首先
select @@global.sql_mode;查看sql_mode 的默认配置包含什么内容,在这个的基础上去掉 only_full_group_by,在配置文件中令 sql_mode=剩下的内容
因为不同版本的mysql默认的sql_mode可能不一致,要根据实际情况修改配置文件,否则会导致mysql无法重启。
注: 如 my.cnf 为只读文件,利用
ll my.cnf查看文件权限,则用root权限修改。
3、重启mysql服务:
service mysql restart
- MySQL: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'sss
- MySQL: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column '
- [mysql] Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'lo
- Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'party.uc.
- mysql:Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column
- Mysql解决SELECT list is not in GROUP BY clause and contains nonaggregated column 问题
- #1055 - Expression of SELECT list is not in GROUP BY clause and contains nonaggregated column this i
- mysql错误:Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'ga
- Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo
- #1055 - Expression of SELECT list is not in GROUP BY clause and contains nonaggregated column this i
- #1055 - Expression of SELECT list is not in GROUP BY clause and contains nonaggregated column this i
- 【问题解决】Expression #30 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'zxj
- MySQL关于"SELECT list is not in GROUP BY clause and contains nonaggregated column"错误
- Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'userinfo.
- Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column
- MySQL报错“Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre”
- [Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated colum
- mysql遇见Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre的问题
- 解决MySql查询语句报Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggre异常的问题
- [Err] 1055 - Expression #4 of SELECT list is not in GROUP BY clause and contains nonaggregated colum