Mysql8版本 only_full_group_by报错解决方案

本文介绍了在MySQL5.7及以上版本中,由于启用only_full_group_by模式导致的SQL查询错误,原因在于SELECT列表中的非聚合字段未包含在GROUPBY子句中。提供了Windows和Linux环境下的解决方案,包括修改my.ini或my.cnf文件以调整sql_mode设置。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

sql查询报错:only_full_group_by解决方案

问题原因:

在 MySQL 5.7 后的版本,当 SQL 语句有 group by 关键词时,有时执行 SQL 会提示如下异常信息:

### 
The error occurred while setting parameters
 Cause: java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'sanyuan_db.sys_user.user_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
; bad SQL grammar []; nested exception is java.sql.SQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'sanyuan_db.sys_user.user_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

造成异常的原因为 MySQL 5.7 版本后默认的 sql 配置是: sql_mode=ONLY_FULL_GROUP_BY,这个配置严格执行了"

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值