MySql 5.7+ ONLY_FULL_GROUP_BY 引发问题解决方法
程序员文章站
2023-12-28 15:21:40
...
一般都是使用group by 引发的异常
-Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘###’…
this is incompatible with sql_mode=only_full_group_by
原因:mysql 5.7+ 版本only_full_group_by SQL 默认开启
其实就是使用了oracle的group规则啦,导致旧版本写的sql无法通过
解决方法:
mysql> SHOW SESSION VARIABLES;
mysql> SHOW GLOBAL VARIABLES;
mysql> select @@sql_mode;
得到sql-mode例如:
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
注意:不要复制,个人数据库配置不同,将所查的sql_mode去除ONLY_FULL_GROUP_BY后重新set
set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION'
ps: 直接设置sql_mode为修改全局变量,只对新建数据库有效,已有数据库需进入后执行上方set代码
set @@sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';
推荐阅读
-
MySql 5.7+ ONLY_FULL_GROUP_BY 引发问题解决方法
-
Mysql数据库报错:select list is not in group by clause and contains .....sql_mode=only_full_group_by问题
-
解决MySQL5.7报SQLSTATE 1055的only_full_group_by问题
-
解决MySQL 5.7.9版本sql_mode=only_full_group_by问题
-
【mysql】执行group by提示only_full_group_by问题解决方法
-
mysql5.7之ONLY_FULL_GROUP_BY问题
-
【mysql问题】完美解决this is incompatible with sql_mode=only_full_group_by
-
Mysql解决only_full_group_by问题
-
MySql5.7版本问题sql_mode=only_full_group_by的完美解决方案
-
mysql5.7 only_full_group_by问题