关于mysql Expression #1的解决方案

本文解决重装MySQL后因only_full_group_by配置导致的数据获取失败问题,提供禁用该配置的方法,确保前后端数据交互正常。

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

完美解决

重装了mysql之后,前台页面获取后台数据老是失败,出现的错误如下

Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'db_srkj_server.t.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 com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'db_srkj_server.t.id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

能看出来是关于only_full_group_by的使用错误。查阅了资料才知道,mysql 5.7后默认开启
sql_mode=only_full_group_by,自己可以去查询一下sql_mode,第一个就是。这个配置的主要意思呢就是select之后的列必须被group by之后的列所包含,简单来说就是:
select a,b from table group by a,b,c; (正确)
select a,b,c from table group by a,b; (错误)
所以一般不使用这个配置。

set @@global.sql_mode 
=’STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION’;

如图设置之后就可以访问后台数据了。还可以把my.ini文件中添加
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再去修改了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值