mysql报错Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregate

Posted xuewudao

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mysql报错Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregate相关的知识,希望对你有一定的参考价值。

原因
聚合查询出现这样的报错是因为mysql设定的mode含有 ONLY_FULL_GROUP_BY
1
mysql> select @@sql_mode;
+-------------------------------------------------------------------------------------------------------------------------------------------+
| @@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 |
+-------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

 

在上面修改的基础上,本人成功的解决方法,

cd /etc/mysql/mysql.conf.d/    

(有的mysql配置文件是 /etc/my.cnf ,而我的Ubuntu16.04 + mysql 5.7.24 下 mysql配置文件是这里 /etc/mysql/mysql.conf.d/)
sudo vim mysqld.cnf
在[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

 

 

如果是docker

要挂载docker容器目录/etc/mysql/mysql.conf.d

把原来的目录里面的文件mysqld.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

以上是关于mysql报错Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregate的主要内容,如果未能解决你的问题,请参考以下文章

windows server 2008 安装MySQL 8.0 遇到报错 1055 - Expression #1 of ORDER BY clause is not in GROUP BY(示例代

MYSQL报错:1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated col

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 nonag

mysql报错Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column问题(示例

mysql报错Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column问题(示例