1. 程式人生 > >mysql5.7.x:this is incompatible with DISTINCT

mysql5.7.x:this is incompatible with DISTINCT

DISTINCT關鍵字經常在MySQL中使用,在mysql5.7以前的版本中一般沒有什麼問題,但是在5.7以後的版本中會遇到這樣的錯誤

Caused by: java.sql.SQLException: Expression #1 of ORDER BY clause is not in SELECT list, references column ‘game.giftbag0_.create_date’ which is not in SELECT list; this is incompatible with DISTINCT

錯誤提示DISTINCT不相容,要麼更改SQL,但是對於開發者來講,sql執行一直都是正常的,可能是mysql 版本升級導致的安全問題,5.7.x安全性提升了很多,解決辦法可以考慮修改MySQL配置檔案,找到對應的my.cnf或者my.ini

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
  • 1

新增該行就ok!

還有一種錯也是不相容的問題導致的

Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column ‘nctest.pivot.id’ which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

這種問題就是sql_mode=only_full_group_by導致的,去掉only_full_group_by就解決了