首页> 开发问题 >服务器问题 服务器问题

MySQL报错:which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mod

作者:小萝卜 2020-05-26 浏览 1869

简介网站换了服务器之后报错:which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mod

换了服务器之后,mysql从5.6也换成了5.7,使用如下sql语句会报错:

select * from my_student group by class_id;

报错:

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

错误的原因是我mysql版本换成了5.7的,使用如下语句查询可知

select @@sql_mode;

里面默认设置了

sql_mode=only_full_group_by

only_full_group_by :使用这个就是使用和oracle一样的group 规则, select的列都要在group中,或者本身是聚合列(SUM,AVG,MAX,MIN) 才行,其实这个配置目前个人感觉和distinct差不多的,所以去掉就好

Windows 服务器直接在my.ini  配置文件添加如下:

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

Linux服务器则在etc/my.cnf配置文件加入上面的代码。

最后重启服务器,OK正常使用。

 

很赞哦! (0)

文章评论

    高端网站建设