MySql version changes, and an error is reported when group by is used for group query sql_mode=only_full_group_by

1. Reasons for the error

After MySQL5.7.5, only_full_group_by becomes one of the default options of sql_mode, which may cause some SQL statements to fail.
For example, when group by is used for group query, an error is reported

Two, the solution

1. Modify sql_mode

-- 查询
select @@global.sql_mode

-- 修改
set @@sql_mode ='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION';

The above is to change the global sql_mode, which is valid for the newly created database.

2. For existing databases

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

In this way, the settings will become invalid after the database is restarted. This is indeed the case. The above method only modifies the value in memory and cannot be changed permanently.

3. Original configuration record

ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

4. New configuration record

Difference: ONLY_FULL_GROUP_BY is deleted

STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION

5. If it is Alibaba Cloud RDS, modify it to the new configuration

  • modify
    Insert picture description here

  • submit
    Insert picture description here

  • Some of the above content comes from the Ant Classroom http://www.mayikt.com/

  • Personal open source project (universal background management system) –> https://gitee.com/wslxm/spring-boot-plus2 , you can check it out if you like

  • This is the end of this article. If you find it useful, please like or pay attention to it. We will continue to update more content from time to time... Thank you for watching!

Guess you like

Origin blog.csdn.net/qq_41463655/article/details/109035668