I accidentally enabled ONLY_FULL_GROUP_BY mode like this:
SET sql_mode = \'ONLY_FULL_GROUP_BY\';
How do I disable it?
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.
The MySQL documentation also specifies the following methods:
sql-mode="<modes>"
in an option file such as my.cnf (Unix operating systems) or my.ini (Windows).--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.
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'
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.
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"
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"