出現的問題
當在SQL中使用group by時可能會出現如下問題:
> 1055 - Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'xxx' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
解決辦法
嘗試解決,一般是在my.cnf文件下的[mysqld]中加入如下內容:
sql_mode='NO_AUTO_VALUE_ON_ZERO,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,
ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,PIPES_AS_CONCAT,ANSI_QUOTES'
然後重啓數據庫,可能會啓不來,原因是MYSQL8以上已經取消了NO_AUTO_CREATE_USER,sql_mode中不能包含這個,將其去掉再次啓動MySQL即可。