0
点赞
收藏
分享

微信扫一扫

解决MySQL 5.8.x版本sql_mode=only_full_group_by问题,this is incompatible with sql_mode=only_full_group_by错误

紫荆峰 2022-05-06 阅读 57

项目场景:今天用DBeaver运行这个sql脚本出错

脚本:

use case1;
select t1.author_id ,t1.live_id	,coalesce (sum(t2.watch_duration)/t1.live_duration,0) as acu
from t1
left join t2 
on (t1.live_id = t2.live_id)
group by t1.author_id ,t1.live_id;

问题描述:sql_mode=only_full_group_by

Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'case1.t1.live_duration' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

原因分析:mysql8.x版本默认开启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';

办法2:
先找到自己mysql安装路径

select @@basedir;

然后进入文件夹找到自己的my.ini配置文件,修改[mysqld]中的内容,添加下面的内容就可以
在这里插入图片描述
一定要加在[mysqld]里面,就是下面这行代码,就是将查询到的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

然后退出数据库,在服务里面重启MySQL就可以
重启也很关键!!
在这里插入图片描述

举报

相关推荐

0 条评论