執行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即可