9

I followed the 2nd answer of this SO question to disable the global option ONLY_FULL_GROUP_BY.

mysql> SELECT @@sql_mode;
+-------------------------------------------------------------------------------------------------------------------------------------------+
| @@sql_mode                                                                                                                                |
+-------------------------------------------------------------------------------------------------------------------------------------------+
| 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 |
+-------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0,00 sec)


mysql> SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
Query OK, 0 rows affected (0,00 sec)


mysql> SELECT @@sql_mode;
+------------------------------------------------------------------------------------------------------------------------+
| @@sql_mode                                                                                                             |
+------------------------------------------------------------------------------------------------------------------------+
| STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+------------------------------------------------------------------------------------------------------------------------+
1 row in set (0,00 sec)

I just discovered that after a mysql service restart, this option is restored.

This is my environment

Server: Localhost via UNIX socket
MySQL 5.7.17-0ubuntu0.16.04.1 
Ubuntu 16.04

I thinked it was in one of the config files, but I'm not able to find it. Can you point me where is it located or how to permanently disable it?

Community
  • 1
  • 1
realtebo
  • 23,922
  • 37
  • 112
  • 189

2 Answers2

19

Found:

I must add a new line into /etc/mysql/mysql.conf.d/mysqld.cnf

Ensure you have a section name [mysqld]

Add after this section name the following

sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

Please, please, please NOTE THIS: This sql_mode is specific for my specific situation and use case; when applying this answer to your case, ensure you understand the principle and not copy/paste litterally.

First: read actual sql_mode

Second: apply changes to sql_mode, and test it

Third: using mysqld.conf or, better, a custom .cnf file is possible, apply the modification to sql_mode as illustrated above

Then restarted

sudo systemctl restart mysql

My settings now is preserved after restart.

realtebo
  • 23,922
  • 37
  • 112
  • 189
4

You can find (or create) config file in the paths listed here - Using Option Files

In config file in [mysqld] section write options you need, for example:

[mysqld]
sql_mode=ONLY_FULL_GROUP_BY
Devart
  • 119,203
  • 23
  • 166
  • 186