mysql 新版本出現(xiàn)group by 語句不兼容問題
1橄妆、 具體出錯提示:
[Err] 1055 - Expression #1 of ORDER BY clause is not in GROUP BY clause and contains nonaggregated column 'information_schema.PROFILING.SEQ' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
1.1滚婉、查看sql_mode
select @@global.sql_mode;
1.2每篷、 查詢出來的值為:
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
2昆婿、去掉ONLY_FULL_GROUP_BY,重新設置值撞蜂。
set @@global.sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
2.1盲镶、上面是改變了全局sql_mode,對于新建的數(shù)據(jù)庫有效蝌诡。對于已存在的數(shù)據(jù)庫溉贿,則需要在對應的數(shù)據(jù)下執(zhí)行:
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';
3、:修改my.cnf(windows下是my.ini)配置文件浦旱,刪掉only_full_group_by這一項
若我們項目的mysql安裝在ubuntu上面宇色,找到這個文件打開一看,里面并沒有sql_mode這一配置項颁湖,想刪都沒得刪宣蠕。
當然,還有別的辦法甥捺,打開mysql命令行抢蚀,執(zhí)行命令
如果 [mysqld] 這行被注釋掉的話記得要打開注釋。
sql_mode=STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION