標籤:執行 dep session gre var user 解決 font func
具體異常資訊如下:
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'aaa.test.age' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by
執行這樣的SQL語句可重現異常 select age, name from test group by name
mysql5.1,不報異常
mysql5.5,不報異常
mysql5.6,不報異常
mysql5.7.22,報異常(具體從5.7哪個版本開始還沒有確定下來,網上有人說5.7.5)
mysql從5.7的某個版本開始調整了預設參數sql_mode值為:
mysql> show variables like 'sql_mode';+---------------+-------------------------------------------------------------------------------------------------------------------------------------------+| Variable_name | Value |+---------------+-------------------------------------------------------------------------------------------------------------------------------------------+| sql_mode | ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |+---------------+-------------------------------------------------------------------------------------------------------------------------------------------+1 row in set (0.00 sec)mysql>
其中ONLY_FULL_GROUP_BY就是影響了上面SQL語句是否報異常
解決方案:
1、改寫SQL語句,畢竟上面的寫法不是標準的SQL語句
2、登陸mysql伺服器,執行以下命令,在global與session級都修改
mysql> set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';mysql> set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
3、結合第2種方法,在my.cnf檔案中,指定sql_mode的值:
[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
註:2與3結合可不用重啟伺服器,且即使重啟配置也依然有效。
mysql異常ERROR 1055 (42000)說明