mysql5.6升级5.7后页面报错很有可能是sql_mode的only_full_group_by原因。
mysql5.7在select后面的字段必须出现在group by后面,或者被聚合函数包裹,不然会抛出以下错误:

Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'XXX' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

具体查看方法:

执行查询语句
select @@global.sql_mode;

若配置中含有only_full_group_by属性则需要关闭。直接在数据库连接工具中执行SET sql_mode是不生效的
要在服务器上找到mysql的配置文件

vi /etc/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'

重启mysql服务就可以了:
service mysqld restart

©著作权归作者所有

发表评论