1. 程式人生 > >mybatis報錯:this is incompatible with sql_mode=only_full_group_by

mybatis報錯:this is incompatible with sql_mode=only_full_group_by

在本地啟動專案後,發現控制檯報如下錯誤

bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'data_show.t.target_number' 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

於是查閱資料,發現有可能是我本地安裝的mysql用的是預設配置,雖然其他專案執行相同的指令碼可以通過,但是不知為何這個專案會報這個錯誤,修改如下配置即可

sudo vim /etc/my.cnf  #沒有的話就建立一個
#將sql_mode 的值改為''
sql_mode = ''

修改完成後,重啟mysql,然後檢視配置

show variables like '%sql_mod%';

最後附上官方的解釋:點選檢視