執行sql報錯 ERROR 1055 (42000): xxx; this is incompatible with sql_mode=only_full_group_by


執行sql 

mysql> SELECT b.pluginId, b.version FROM ( SELECT t.plugin_id AS pluginId, t.version FROM table1 as  t WHERE t.is_deploy = 1 AND t.is_delete = 0 ) AS b GROUP BY b.pluginId ;

報錯信息如下
ERROR 1055 (42000): Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'b.version' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

這句錯誤的意思是查詢列表 select 的字段中有字段沒有出現在gruop by子句中,不符合 數據庫sql_mode設置的only_full_group_by規則

這是一個sql規則,可以選擇遵從也可以選擇不遵從。

我這里的sql有這個需求,所以最終選擇不遵從這個規則

解決辦法:修改sql_model

在linux 環境下修改  /etc/my.cnf文件  

找到sql_model 標簽刪除 only_full_group_by

如果沒有sql_model則需要在[mysqld]標簽下邊添加一個

添加的內容可以先用  select @@sql_mode; 語句查看下包括哪些規則,然后拷貝出來查詢內容 去除掉only_full_group_by 復制在 /etc/my.cnf文件里然后保存

例如:

# For advice on how to change settings please see
# http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html
 [mysqld]
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
#
# Remove leading # and set to the amount of RAM for the most important data
# cache in MySQL. Start at 70% of total RAM for dedicated server, else 10%.
# innodb_buffer_pool_size = 128M
#
# Remove leading # to turn on a very important data integrity option: logging
# changes to the binary log between backups.
log_bin=mysql-bin
server-id=101014

接下來使用 service mysqld restart  重啟mysql即可生效

在windows環境下修改安裝目錄下的my.ini 文件即可,和上邊相同,然后重啟mysql即可


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM