ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregate

在mysql 5.7初次使用group by时会出现错误,首先表信息如下:
       ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘test.score.id’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

select c_name,id from score group by c_name;

ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregate_第1张图片
查看一下MySQL5.7的检查模式

ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregate_第2张图片

通过修改my.cnf或者my.ini配置文件去掉ONLY_FULL_GROUP_BY一项(如果没有这个配置项则新建)
在文件里加上下面一行

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
此时就不会在出现ONLY_FULL_GROUP_BY
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregate_第3张图片

你可能感兴趣的:(mysql)