Disable ONLY_FULL_GROUP_BY

后端 未结 27 1892
既然无缘
既然无缘 2020-11-22 00:22

I accidentally enabled ONLY_FULL_GROUP_BY mode like this:

SET sql_mode = \'ONLY_FULL_GROUP_BY\';

How do I disable it?

27条回答
  •  南方客
    南方客 (楼主)
    2020-11-22 00:52

    I have noticed that @Eyo Okon Eyo solution works as long as MySQL server is not restarted, then defaults settings are restored. Here is a permanent solution that worked for me:

    To remove particular SQL mode (in this case ONLY_FULL_GROUP_BY), find the current SQL mode:

    SELECT @@GLOBAL.sql_mode;
    

    copy the result and remove from it what you don't need (ONLY_FULL_GROUP_BY)

    e.g.:

    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
    

    to

    STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    

    create and open this file:

    /etc/mysql/conf.d/disable_strict_mode.cnf
    

    and write and past into it your new SQL mode:

    [mysqld]
    sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    

    restart MySQL:

    sudo service mysql restart
    

    Or you can use ANY_VALUE() to suppress ONLY_FULL_GROUP_BY value rejection, you can read more about it here

提交回复
热议问题