解决Mysql:1055 – Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated

解决:

方法一:修改配置。去掉ONLY_FULL_GROUP_BY

如果是Linux,就在配置文件(my.cnf)中修改 sql_mode 的配置(在/usr/local/etc/my.cnf路径下)并重启mysql服务。

$ vim /usr/local/etc/my.cnf
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
set @@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的my.ini配置文件中去修改:

在[mysqld]下添加sql_mode=’STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION’,然后保存并重启服务。

留下评论