码迷,mamicode.com
首页 > 数据库 > 详细

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

时间:2020-06-14 18:37:34      阅读:68      评论:0      收藏:0      [点我收藏+]

标签:sub   gate   sudo   聚合   visio   tab   内容   str   div   

原因
聚合查询出现这样的报错是因为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

标签:sub   gate   sudo   聚合   visio   tab   内容   str   div   

原文地址:https://www.cnblogs.com/xuewudao/p/13125764.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!