mysql由5.7.22升級5.7.25版本的時候報Err1055異常
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:
Expression #1 of ORDER BY clause is not in GROUP BY clause and contains
nonaggregated column 'callcenter.CREATETIME' which is not functionally
dependent on columns in GROUP BY clause; this is incompatible
with sql_mode=only_full_group_by
修復方法:
-
首先登陸mysql
mysql -uroot -p
-
登陸後使用命令
SELECT @@sql_mode;
,查看sql_mode
中確實有ONLY_FULL_GROUP_BY
mysql> SELECT @@sql_mode; +-------------------------------------------------------------------------------------------------------------------------------------------+ | @@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的sql_mode
在
/etc/my.cnf
文件里加sql_mode
屬性,值爲上一步查詢出來的,去掉ONLY_FULL_GROUP_BY
即可
如下:# For advice on how to change settings please see # http://dev.mysql.com/doc/refman/5.7/en/server-configuration-defaults.html [mysqld] # # 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 # =====省略一部分內容===== # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # =============這裏就是修改後的sql_mode================== sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION' log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
-
重啓Mysql服務就可以
service mysql restart
如果系統沒有上面的重啓命令
參考地址 https://blog.csdn.net/cx136295988/article/details/76690722
提示:
網上有些辦法是用如下的sql指令去修改這個值,但是每次重啓後會復原,只有修改my.cnf重啓纔有效果。
SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));