之前在做springboot的项目的时候,运行的时候页面显示500错误,然后控制台这边显示如下错误:
[Err] 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'gsms.shield_infomaction.shield_Id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
奇怪的很,以前从来没遇见过这种错误,上网查了查,终于找到解决方案。
原因:
我安装的是mysql5.7+,默认是开启了 only_full_group_by 模式的,从而导致GROUP BY 语句报错
解决:
第一步:查看当前的sql_mode
首先在cmd终端进入到你的mysql的bin目录下,通过这个命令可以查看当前的sql_mode:select @@sql_mode
第二步:
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';
第三步:
set session sql_mode=
'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
接下来就大功告成啦!