mysql 5.7版本groupby不可用

@mysql 5.7版本groupby不可用

mysql5.7默认不支持group by功能,如果不取消这个设置,写出来的sql严格遵守oracle得规范,但是很麻烦,而且以前项目sql要重写,所以需要修改参数.

报错:
LECT list is not in GROUP BY clause and contains nonaggregated column ‘database_tl.emp.id’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
实际是就是所有查询得字段名需要在group by里包含,否则不通过.

修改步骤(linux环境)
1,找到mysql配置文件,这里5.7和别的也不一样,不在/etc/my.cnf,没这个配置文件,在/etc/mysql/mysql.conf.d 下的mysqld.cnf
2,新增一行

sql_mode        = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

这样,之前项目中groupby 语句就可以使用了

以下为第二种设置方法
1,检查mysql数据库是否可以使用group by得方法

mysql> 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_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |

+-------------------------------------------------------------------------------------------------------------------------------------------+

1 row in set (0.00 sec)

2,设置为空

mysql> set @@GLOBAL.sql_mode='';

猜你喜欢

转载自blog.csdn.net/zdrewq/article/details/83586792