這兩天一直忙着遷移服務器,數據庫,趕上這樣或者那樣的小故障。 在這裏也隨筆記一下。html
因爲部分阿里雲RDS數據庫過時,再加上相關費用問題,全部公司決定只有線上環境使用阿里RDS數據庫, 其餘環境都自搭建數據庫。mysql
線上阿里雲數據庫 Mysql 5.6
自建服務器數據庫 Mysql 5.7
sql
遷移完測試的數據庫後, 小小測試一下, 大概沒有什麼問題。 下午的時候產品找過了說某些個功能不能用了, 一查日誌。數據庫
Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column '1066export.ebay_order_items.TransactionID' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
一看sql(此處來源於網絡), 你們也就知道是什麼問題。服務器
select libelle,credit_initial,disponible_v,sum(montant) as montant FROM fiche,annee,type where type.id_type=annee.id_type and annee.id_annee=fiche.id_annee and annee = year(current_timestamp) GROUP BY libelle order by libelle asc
而後一查官網手冊, 有以下一段話, 大體的意思是自 MySQL 5.7.5
以後, 默認 ONLY_FULL_GROUP_BY
模式是開啓的, ONLY_FULL_GROUP_BY
必須搭配彙集函數才能使用。網絡
ONLY_FULL_GROUP_BY : Reject queries for which the select list, HAVING condition, or ORDER BY list refer to nonaggregated columns 、that are neither named in the GROUP BY clause nor are functionally dependent on (uniquely determined by) GROUP BY columns. As of MySQL 5.7.5, the default SQL mode includes ONLY_FULL_GROUP_BY. (Before 5.7.5, MySQL does not detect functional dependency and ONLY_FULL_GROUP_BY is not enabled by default
因爲剛接手這代碼不久,且已經在線上運行了一年多, 修改sql
有必定的風險。 因此打算只修改測試服務器數據庫的 Mode
。函數
mode
SELECT @@sql_mode;
獲得測試
ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
/etc/my.cnf
(可能有些服務器不是這個路徑)加入以下配置this
[mysqld] sql_mode = "STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
service mysqld restart
修改完後, 測試阿里雲