idea报错“未知错误”:which is not functionally dependent on columns in GROUP BY clause解决方案

columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by mysql8.0解决办法
控制台报错如下:
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘jol.solution.nick’ 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选项。我的版本是mysql8.0以上的

Windows解决办法:
先查询查看sql_mode中的内容

select @@GLOBAL.sql_mode;
+-----------------------------------------------------------------------------------------------------------------------+
| @@GLOBAL.sql_mode                                                                                                     |
+-----------------------------------------------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION |
+-----------------------------------------------------------------------------------------------------------------------+

解决办法有两种,第一种是临时解决,不治本,数据库重启还会重新出现此问题,第二种是修改my.ini配置文件,治本,也方便
办法1:
将查询到的sql_mode中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;
+-----------+
| @@basedir |
+-----------+
| E:\mysql\ |
+-----------+

然后进入文件夹找到自己的my.ini配置文件,修改[mysqld]中的内容,添加下面的内容就可以
idea报错“未知错误”:which is not functionally dependent on columns in GROUP BY clause解决方案_第1张图片
idea报错“未知错误”:which is not functionally dependent on columns in GROUP BY clause解决方案_第2张图片
一定要加在[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就可以
idea报错“未知错误”:which is not functionally dependent on columns in GROUP BY clause解决方案_第3张图片

idea报错“未知错误”:which is not functionally dependent on columns in GROUP BY clause解决方案_第4张图片

你可能感兴趣的:(mysql,JAVA,数据库,mysql,java,数据库)