sql_mode设置groupby模式

解决sql语法group by模式导致的sql语法问题

#具体报错
which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

重启mysql设置失效

select @@global.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';

关闭会话设置失效

select @@sql_mode;

SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

永久生效

#修改mysql配置文件my.cnf添加一下内容、最后再重启,
[mysqld]
sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'

注意:更改配置后必须要重启应用(重新建立新的连接)

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