mysql 8.0下的SELECT list is not in GROUP BY clause and contains nonaggregated column

mysql的版本

mysql> select version();
+-----------+
| version() |
+-----------+
| 8.0.12 |
+-----------+

在執行group  by時遇到報錯,具體如下

mysql> select * from api_properties GROUP BY file_id order by file_id;
1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 
'bim.api_properties.id' which is not functionally dependent on columns in GROUP BY clause; this is
incompatible with sql_mode=only_full_group_by

記得上次在5.7下也遇到了同樣的問題  5.7的

win下修改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

重啓mysql

啓動失敗,描述爲

2019-08-27T09:22:54.827016Z 0 [ERROR] [MY-011071] [Server]
D:\phpstudy_pro\COM\..\Extensions\MySQL8.0.12\\bin\mysqld.exe: 
Error while setting value 
'STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,
NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' to 'sql_mode'

2019-08-27T09:22:54.827016Z 0 [ERROR] [MY-010119] [Server] Aborting

2019-08-27T09:22:54.828016Z 0 [Note] [MY-010120] [Server] Binlog end

NO_AUTO_CREATE_USER 在 5.7.* 的日誌中提到已廢除該模式,在 8.0.11 中刪除了

修改設置爲

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,
NO_ENGINE_SUBSTITUTION

重啓mysql,問題解決

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章