mysql异常[Err] 1055 - GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

MySQL error message is as follows: 

Expression #1 of SELECT list is not in GROUP BY clause and contains
nonaggregated column ‘数据库名.表名.字段名’ which is not functionally dependent
on columns in GROUP BY clause; this is incompatible with
sql_mode=only_full_group_by

Reason for error

The default sql configuration for MySQL version 5.7.5 and above is: sql_mode="ONLY_FULL_GROUP_BY". When many upgrade from 5.6 to 5.7, for the sake of syntax compatibility, most of them will choose to adjust sql_mode to keep it consistent with 5.6, in order to be as compatible with the program as possible.

Since the setting of ONLY_FULL_GROUP_BY is turned on, if the selected field is not in group by, and the selected field does not use an aggregate function (SUM, AVG, MAX, MIN, etc.), then this SQL query is considered illegal by MySQL and will be reported. mistake.

solution

View sql_mode

select @@GLOBAL.sql_mode;

Modify sql_mode

SET @@GLOBAL.sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

Guess you like

Origin blog.csdn.net/watson2017/article/details/132061649