this is incompatible with sql_mode=only_full_group_by

The project changed a database and reported an error:

; bad SQL grammar []; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Expression #2 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'kjwl.a.description' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

 

The main reason is that some sql group by statements are not standardly written, and an error will be reported when the database setting grammar rules are relatively strict. If you don't want to change the sql statement, you need to change the mysql settings:

Remove the only_full_group_by item from sql_mode.

You can enter SELECT @@sql_mode; on the mysql command line to check the current sql_mode settings.

 

Then you can execute:

 

set @@GLOBAL.sql_mode='';

set sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

i.e. reset this value. But there is still a problem, that is, the settings will be restored after restarting mysql. So the above settings should be placed in the mysql configuration file, the default is /etc/my.cnf

Add under the [mysqld] item (as long as there is no only_full_group_by in it)

 

# to solve problem: this is incompatible with sql_mode=only_full_group_by

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

 

 

There is also a saying on the Internet that the added items are written like the statement of executing the command, but when I tried it with my own version, it failed to start, and the above method can be used.

Reference (with changes): http://www.cnblogs.com/jim2016/p/6322703.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325700180&siteId=291194637