解决 mysql8 报错 this is incompatible with sql_mode = only_full_group_by

发布于 2021-05-21 18:05 阅读 2103

报错内容

Error Code: 1055. Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column '{field}' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by 0.053 sec

确认运行模式

mysql> select @@global.sql_mode;

ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

重新设置运行模式

vi /etc/my.cnf
[mysqld]
# 去掉ONLY_FULL_GROUP_BY即可
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

重启服务

service mysqld restart

广而告之,我的新作品《语音助手》上架Google Play了,欢迎下载体验