Disable ONLY_FULL_GROUP_BY

后端 未结 27 1283
既然无缘
既然无缘 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:56

    This is a permanent solution for MySql 5.7+ on Ubuntu 14+:

    $ sudo bash -c "echo -e \"\nsql_mode=IGNORE_SPACE,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION\"  >> /etc/mysql/mysql.conf.d/mysqld.cnf"
    $ sudo service mysql restart
    # Check if login attempt throws any errors
    $ mysql -u[user] -p # replace [user] with your own user name
    

    If you are able to login without errors - you should be all set now.

    0 讨论(0)
  • 2020-11-22 00:58

    The MySQL documentation also specifies the following methods:

    • Set sql-mode="<modes>" in an option file such as my.cnf (Unix operating systems) or my.ini (Windows).
    • To set the SQL mode at server startup via the command line, use the --sql-mode="<modes>" option.

    *Where <modes> is a list of different modes separated by commas.

    To clear the SQL mode explicitly, set it to an empty string using --sql-mode="" on the command line, or sql-mode="" in an option file.

    I added the sql-mode="" option to /etc/my.cnf and it worked.

    This SO solution discusses ways to find out which my.cnf file is being used by MySQL.

    Don't forget to restart MySQL after making changes.

    0 讨论(0)
  • 2020-11-22 00:58

    with MySQL version 5.7.28 check by using
    SELECT @@sql_mode; and update with

    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'
    
    0 讨论(0)
  • 2020-11-22 00:59

    Be careful using

    SET sql_mode = '' 
    

    This actually clears all the modes currently enabled. If you don't want to mess with other settings, you'll want to do a

    SELECT @@sql_mode 
    

    first, to get a comma-separated list of the modes enabled, then SET it to this list without the ONLY_FULL_GROUP_BY option.

    0 讨论(0)
  • 2020-11-22 00:59

    For MySql 8 you can try this one. (not tested on 5.7. Hope it also works there)

    First open this file

    sudo vi /etc/mysql/my.cnf and paste below code at the end of above file

    [mysqld]
    sql_mode = "STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
    
    0 讨论(0)
  • 2020-11-22 00:59

    You can disable it using the config file my.cnf :

    $ mysql --verbose --help | grep my.cnf
    

    So in macOS 10.12, it's at usr/local/etc/my.cnf. You can edit sql_mode here:

    # Default Homebrew MySQL server config
    [mysqld]
    # Only allow connections from localhost
    bind-address = 127.0.0.1
    sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
    
    0 讨论(0)
提交回复
热议问题