其他分享
首页 > 其他分享> > [Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated解决

[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated解决

作者:互联网

今天在docker容器中搭建mysql主从同步的时候,发现了如下报错:
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated

问题背景:
使用的mysql数据库版本为:5.7
在从库中执行如下命令:start slave

然后就报如上错误

[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column ‘information_schema.PROFILING.SEQ’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

分析原因

这个问题主要是由于sql_mode引起,所以先查看sql_mode后修改即可,主要是去除only_full_group_by

解决方案:

通过mysql客户端连接数据库。比如navicat、sqlyog等,运行如下命令:
SELECT @@sql_mode;
可以看到查询结果为:
在这里插入图片描述
上面的这个查询结果是执行修改了SQL_MODE之后的查询结果,实际在还没有修改之前里面应该有only_full_group_by,然后修改SQL_MODE的值即可,运行如下命令:
SET sql_mode=(SELECT REPLACE(@@sql_mode,‘ONLY_FULL_GROUP_BY’,’’));

当再次执行start slave命令的时候,则mysql就不会再报上面那个错误了。

本次出行的这个错误是在docker容器中出现的,如果是使用的mysql安装包安装的mysql,则需要去修改配置文件my.ini

在my.ini中添加如下配置:
[mysql]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

可以看出,这个跟上面最终的查询结果一致:
在这里插入图片描述

标签:nonaggregated,GROUP,NO,clause,mysql,mode,sql
来源: https://blog.csdn.net/miachen520/article/details/122390084