简体   繁体   中英

How to enable ONLY_FULL_GROUP_BY in MySQL

I have disabled ONLY_FULL_GROUP_BY by using SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); . Now I want to restore the default settings.

Is it possible to enable the ONLY_FULL_GROUP_BY in MySQL again?

Thanks in advance

为避免其他配置出现问题,请使用 CONCAT:

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

If you are using Laravel, you could do this on runtime instead of making a global setting

//disable ONLY_FULL_GROUP_BY
DB::statement("SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));");

//Your SQL goes here - The one throwing the error (:

//re-able ONLY_FULL_GROUP_BY
DB::statement("SET sql_mode=(SELECT CONCAT(@@sql_mode, ',ONLY_FULL_GROUP_BY'));");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM