mysql5.7報錯this is incompatible with sql_mode=only_full_group_by

下載安裝的是最新版的mysql5.7.x版本,默認是開啓了 only_full_group_by 模式的,但開啓這個模式後,原先的 group by語句就報錯,而後又把它移除了。mysql

一旦開啓 only_full_group_by ,感受,group by 將變成和 distinct 同樣,只能獲取受到其影響的字段信息,沒法和其餘未受其影響的字段共存,這樣,group by 的功能將變得十分狹窄了sql

only_full_group_by 模式開啓比較好。數據庫

由於在 mysql 中有一個函數: any_value(field) 容許,非分組字段的出現(和關閉 only_full_group_by 模式有相同效果)。函數

 

具體出錯提示:

[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_bythis

 

一、查看sql_mode

    select @@global.sql_mode;spa

查詢出來的值爲:

    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_SUBSTITUTIONcode

 

二、去掉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';orm

三、上面是改變了全局sql_mode,對於新建的數據庫有效。

相關文章
相關標籤/搜索