Disable ONLY_FULL_GROUP_BY

后端 未结 27 1295
既然无缘
既然无缘 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 01:14

    On MySQL 5.7 and Ubuntu 16.04, edit the file mysql.cnf.

    $ sudo nano /etc/mysql/conf.d/mysql.cnf
    

    Include the sql_mode like the following and save the file.

    [mysql]
    sql_mode=IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    

    Observe that, in my case, I removed the mode STRICT_TRANS_TABLES and the ONLY_FULL_GROUP_BY.

    Doing this, it will save the mode configuration permanently. Differently if you just update the @@sql_mode through MySQL, because it will reset on machine/service restart.

    After that, to the modified configuration take in action, restart the mysql service:

    $ sudo service mysql restart
    

    Try to access the mysql:

    $ mysql -u user_name -p
    

    If you are able to login and access MySQL console, it is ok. Great!

    BUT, if like me, you face the error "unknown variable sql_mode", which indicates that sql_mode is an option for mysqld, you will have to go back, edit the file mysql.cnf again and change the [mysql] to [mysqld]. Restart the MySQL service and do a last test trying to login on MySQL console. Here it is!

提交回复
热议问题