866

I accidentally enabled ONLY_FULL_GROUP_BY mode like this:

SET sql_mode = 'ONLY_FULL_GROUP_BY';

How do I disable it?

Dharman
  • 30,962
  • 25
  • 85
  • 135
ZviBar
  • 9,758
  • 6
  • 25
  • 30
  • 61
    Have you tried `SET sql_mode = ''`? – Tripp Kinetics May 28 '14 at 20:25
  • It works! You can post it as an answer. – ZviBar May 28 '14 at 20:26
  • 7
    Why would you want to disable a mode that makes MySQL better comply with SQL standards, and one, too, that teaches you to be more careful in writing your queries? – Andriy M May 29 '14 at 08:11
  • This is a good question with the release of mySQL 5.7 which ships with this mode enabled by default. Checking your setup in mysql as per Taran's answer http://stackoverflow.com/a/31058962/438089 and copying the result before adding these options, removing the ONLY_FULL_GROUP_BY (and I remove the "zero dates" ones too) into the line as per br3nt's answer http://stackoverflow.com/a/33476480/438089 (In ubuntu the path is /etc/mysql/my.cnf) and restarting mysql seems to work well. – billythekid Dec 10 '15 at 12:24
  • 51
    As of Mysql 5.7 you may, alternatively, use the ANY_VALUE(`column`) function to retrofit your query. See doc [here](https://dev.mysql.com/doc/refman/5.7/en/miscellaneous-functions.html) – Qoheleth-Tech May 23 '16 at 16:59
  • 6
    @AndriyM I'll need to use this soon because I'm porting a whole load of old applications to a new server and they need to work, whether I have the source or not. – Jaydee May 27 '16 at 13:40
  • @Qoheleth-Tech - that's very useful - was searching for something like this function and didn't know it existed. thanks for the tip! – But those new buttons though.. Jun 16 '16 at 16:19
  • 17
    @AndriyM Because if I am grouping by a unique index column, then I ALREADY know that every row will be unique - adding a separate group by command for every. single. column. in the table is a royal pain. – Benubird Jun 23 '17 at 11:58
  • 1
    @Benubird: Yes, that's the one legitimate use case for this mode, something I obviously didn't realise (or not immediately, anyway) at the time. Touché. – Andriy M Jun 23 '17 at 12:14
  • before trying to disable it, I recommend seeing this https://stackoverflow.com/a/38551525/3160597 – azerafati Jul 08 '17 at 13:02
  • @ZviBar - please update the right answer according to comments bellow – Mladen Janjetovic Nov 05 '17 at 14:25
  • @Benubird Is it a pain though? Can't you just refer to the columns by their ordinal and put "group by 1,2,3,4,5" at the end? Our data architect followed this advice. He set the sql_mode to '' globally across the whole database, then when an all zero date made it's way into a table it took down an application on two separate occasions. – user988346 Nov 17 '20 at 08:45
  • alternatively, for any specific query - you can also use any_value(). https://dev.mysql.com/doc/refman/5.7/en/group-by-handling.html – Channa Jun 24 '21 at 05:20
  • in my case just having SET sql_mode = '' in the ini file was not enough. I needed to populate it with something for MySQL to recognize the change; in my case I just changed it to SET sql_mode = 'ERROR_FOR_DIVISION_BY_ZERO' – Philip Sep 18 '21 at 10:37
  • If you are working over some mysql client then set session sql_mode='something or empty'; will help. – Haisum Usman Jun 10 '22 at 17:20
  • The only correct answer to this question is: [MySQL Handling of GROUP BY](https://dev.mysql.com/doc/refman/8.0/en/group-by-handling.html). Please read it before upvoting this question (or any of the "lot of" _answers_ ) – Luuk Jun 26 '22 at 07:51

38 Answers38

1596

Solution 1: Remove ONLY_FULL_GROUP_BY from mysql console

mysql > SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

you can read more here

Solution 2: Remove ONLY_FULL_GROUP_BY from phpmyadmin

  • Open phpmyadmin & select localhost
  • Click on menu Variables & scroll down for sql mode
  • Click on edit button to change the values & remove ONLY_FULL_GROUP_BY & click on save. enter image description here
Eyo Okon Eyo
  • 16,326
  • 2
  • 13
  • 17
  • 15
    This solution work fine on mySQL 5.7.11 and should be the accepted one. The accepted answer doesn't work on new version of mySQL – Anyone_ph Apr 14 '16 at 06:54
  • 1
    Shouldn't there be a comma as part of the seach? `'ONLY_FULL_GROUP_BY,',''` – Jens Bodal May 11 '16 at 19:57
  • 1
    @JensBodal most probably. But, `ONLY_FULL_GROUP_BY` could also come last right? So it could also be `',ONLY_FULL_GROUP_BY',''` – nawfal May 20 '16 at 08:49
  • 8
    Just ensured. It doesn't matter `REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')`, MySQL anyway removes unwanted commas from the record. OP's answer is correct. – nawfal May 21 '16 at 03:47
  • 52
    This works, but when I restart the mysql server, defaults are restored... why? is there a persistent solution? Thanks! – Vincent Pazeller Nov 16 '16 at 09:15
  • 72
    To answer to my question (persistent solution): you have to put the description of sql_mode inside a my.cnf file (/etc/my.cnf for instance) and restart the server. For instance, insert (below the [mysqld] section) sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" – Vincent Pazeller Nov 22 '16 at 10:44
  • i also confirm as working solution for 5.7.16 thanks – Lukas Liesis Nov 22 '16 at 21:52
  • What about just setting the session.sql_mode only? That's more portable in many cases as you can put that in your script(s). – TheRealChx101 Apr 16 '17 at 22:20
  • @TheRealChx101 simply replace global with session, see [here](http://mechanics.flite.com/blog/2013/02/12/why-i-use-only-full-group-by/) – Eyo Okon Eyo Apr 18 '17 at 08:42
  • 1
    Please note that @VincentPazeller's comments here are still valid - but in my version 5.7.18, I needed to use `sql-mode=` instead of `sql_mode=` (note the dash instead of an underscore) – Warren Sergent Apr 27 '17 at 23:42
  • In my case this failed, with message "Job for mysql.service failed because the control process exited with error code. See 'systemctl status mysql.service' and 'journalctl -xe' for details." I am using - Server version: 5.7.15-0ubuntu0.16.04.1 (Ubuntu) , had to revert back -- I missed the section [mysqld] – almaruf Jul 20 '17 at 14:15
  • 2
    I've fixed it by adding sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION" into my.inf. Anywhere. It works even after rebooting. – Diego Sagrera Nov 10 '17 at 03:01
  • 72
    `GLOBAL` did not work for me, but `SESSION` did.`SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));` – Andre Jan 04 '18 at 07:20
  • 1
    I was close to throwing my mouse into my screen because i couldnt find any person that has a proper solution to this or at least one that gets explained. Thank you for this you saved me kinda. – Johannes Jun 12 '18 at 13:43
  • Plesk enabled this option on its own with an update and I found this solution by googleing for the error message. You literally just safed my butt, mate. – Chris S. Sep 25 '18 at 07:11
  • 1
    MySQL 5.7.22, replacing GLOBAL with SESSION works for me. – Hoang Duc Nguyen Oct 02 '18 at 03:36
  • 3q, It's useful after I set both GLOBAL and SESSION – ryanlee Dec 22 '18 at 06:59
  • 2
    Access denied; you need (at least one of) the SUPER privilege(s) for this operation. I have faced this error while removing only full group by –  Feb 26 '19 at 06:32
  • The solución that work for me is the following: SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','')); – Jorge Santos Neill Feb 26 '19 at 18:35
  • This solution is temporary. Please update you comment with permanent solution. – Oleg Samorai Mar 29 '19 at 16:32
  • solution 1 worked straight away for me. Opened MySQL workbench, ran the query mentioned in solution 1 and restarted the application. voila it worked.. – Suresh Jul 19 '19 at 15:24
  • There should be a warning that this will copy the `SESSION sql_mode` value to the `GLOBAL sql_mode` value, affecting only all future connections and that the global/session values are not inherited from each other during the current session. As there seems to be some confusion as to how session and global work. In this instance the OP would have a resulting `GLOBAL sql_mode=""` and `SESSION sql_mode="ONLY_FULL_GROUP_BY"` which may not be desired. – Will B. Dec 31 '19 at 21:16
  • This acts as a temporary solution for me. After a certain period of time, I have to run the query again and re-run the spring boot jar for it to work – Naanavanalla Aug 02 '20 at 14:37
  • Remember to reconnect to the database. – Miquéias Francisco Jan 08 '21 at 00:29
  • NOTE: changing the sql_mode will not affect stored procedures. So you need to drop and execute SP again to take affect – Abeer Sul Jan 10 '21 at 21:36
  • for MAMP PRO, under File > Open Template. I found a my.cnf template in there. There was a sql_mode variable set in there. Changing that there makes it a permanent change. – Pierre-Verthume Larivière Jul 06 '21 at 16:14
  • I'm in Linux and the instructions for removing ONLY_FULL_GROUP_BY worked in the terminal, but did not exactly solve my problem. I am using Cold Fusion, and apparently Cold Fusion restarts MySql every time you start a query -- so MySql goes back to its default. I was able to solve the problem by putting the line in my query. – Betty Mock Oct 26 '22 at 21:38
  • I am baffled about why this option is defaulting. It makes no sense to me. If I group-by I mean to do a roll-up, and I certainly don't want to roll-up on the unaggregated fields -- I want the sums at each sort break. Can anyone explain why this mode has been created? – Betty Mock Oct 26 '22 at 21:41
431

Update:

enter image description here

To keep your current mysql settings and disable ONLY_FULL_GROUP_BY I suggest to visit your phpmyadmin or whatever client you are using and type:

SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY','') copy_me

next copy result to your my.ini file.

mint: sudo nano /etc/mysql/my.cnf

ubuntu 16 and up: sudo nano /etc/mysql/my.cnf

ubuntu 14-16: /etc/mysql/mysql.conf.d/mysqld.cnf

Caution! copy_me result can contain a long text which might be trimmed by default. Make sure you copy whole text!


old answer:

If you want to disable permanently error "Expression #N of SELECT list is not in GROUP BY clause and contains nonaggregated column 'db.table.COL' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by" do those steps:

  1. sudo nano /etc/mysql/my.cnf
  2. Add this to the end of the file

    [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"
    
  3. sudo service mysql restart to restart MySQL

This will disable ONLY_FULL_GROUP_BY for ALL users

breq
  • 24,412
  • 26
  • 65
  • 106
  • 2
    for me, setting the mysqld tag on the same line didn't work, but is did work with a line break :) thanks – bloub Jun 21 '16 at 14:55
  • 35
    For ubuntu, the file where custom config values go is `/etc/mysql/mysql.conf.d/mysqld.cnf` – knb Aug 23 '16 at 12:02
  • 5
    This worked for Ubuntu 16.04 (14 to 16 upgrade woes..). The /etc/mysql/my.cnf is the correct file. The file mentioned by knb is included within this my.cnf file, in 16.04 at least (configuration is now split up into multiple files). – jwinn Dec 30 '16 at 04:52
  • Don't blindly replace the value with an arbitrary one ! Check the current value, and just remove what you don't want. In other words, use the value from the best non-selected answer : Execute `SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));` to avoid making a mistake. Anyway, glad you gave the config file's location. – Balmipour Feb 28 '17 at 23:19
  • It's funny - I could spend years in college learning about software and database in particular. Therefore, I expect GROUP BY to work with some degree of certainty based on my training and course instruction plus resources like MDN and w3schools. Then, all of a sudden I encounter MySQL in production and learn about some non-compliance issue centered around this topic. This post specifically has been visited 100,000. – ThisClark Mar 01 '17 at 05:47
  • 4
    Use "SELECT @@sql_mode;" to see what modes are currently on before making changes. – Zbigniew Ledwoń Jun 29 '17 at 09:38
  • 1
    the actual place where you'll see `[mysqld]` might not be in this file, it might be in an include directory. Use this command first: `grep -R "\[mysqld\]" *` to see what's there - and for that matter try `grep -R "\bsql_mode\b" *` – Oliver Williams Jan 23 '18 at 20:12
  • Indeed, the actual file I needed to edit was located at /etc/mysql/mysql.conf.d/mysqld.cnf (Ubuntu 16.04) – Matt Kieran Feb 25 '18 at 14:15
  • Be careful also that the result from the SELECT REPLACE Query ends up with a leading comma. This may not hurt anything but I would not want to take a chance – Burndog Jun 07 '18 at 17:50
  • On Ubuntu 18.04.2 I cannot make this pernanent. I edited the file `/etc/mysql/conf.d/mysql.cnf` but the setting is still there, If I check with `SELECT @@sql_mode`. I also rebooted the mashine - still there – rubo77 Mar 22 '19 at 07:15
  • 1
    old answer > new answer – Robert Sinclair Dec 21 '19 at 03:29
  • 18
    On mysql 8.0.22 for me (on Digital Ocean `/etc/mysql/mysql.conf.d/mysqld.cnf` ) this needed to remove one "NO_AUTO_CREATE_USER" to work or mysql would not start ```STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION``` – tristanbailey Jan 15 '21 at 14:47
255

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.

Machavity
  • 30,841
  • 27
  • 92
  • 100
Taran
  • 12,822
  • 3
  • 43
  • 47
  • What's the best way to do this: `then SET it to this list without the ONLY_FULL_GROUP_BY option.`? – Kevin Meredith Dec 18 '15 at 17:37
  • 4
    @KevinMeredith my reading of the [docs](http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html) is there's no way to turn one mode on/off at a time – all the examples require you to supply a comma-separated list of the ones you want - e.g. `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';` – William Turrell Dec 26 '15 at 00:26
  • 2
    If this is a permanent change, edit my.cnf with a line like this: `sql_mode=`, then stop and start your server. Follow the docs for your operating system for the location of, and best way to edit, my.cnf. – blackwood Jul 11 '16 at 14:06
120
    mysql> set global sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
    mysql> set session sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';
    mysql> exit;
brwngrldev
  • 3,664
  • 3
  • 24
  • 45
WeiYuan
  • 5,922
  • 2
  • 16
  • 22
116

Give this a try:

SET sql_mode = ''

Community Note: As pointed out in the answers below, this actually clears all the SQL modes currently enabled. That may not necessarily be what you want.

Bhargav Rao
  • 50,140
  • 28
  • 121
  • 140
Tripp Kinetics
  • 5,178
  • 2
  • 23
  • 37
  • 12
    Wow, `''` = `'full group by is disabled'`? MySQL does some pretty dumb things but that one is up there. – Aaron Bertrand May 28 '14 at 20:35
  • 48
    I think this basically disables any sql mode; – ZviBar May 28 '14 at 20:40
  • This didn't work for me. I see `0 rows affected` and my query still doesn't work: `Error Code: 1055. Expression #6 of SELECT list is not in GROUP BY clause and contains nonaggregated column ...` – Max Heiber Jan 06 '16 at 16:48
  • As stated by ghanbari, it's doesn't work, on my side tried on 5.7.11 – Anyone_ph Apr 14 '16 at 06:52
  • maybe you can try my method below and it's worked on 5.7.9 up. – WeiYuan Apr 27 '16 at 17:32
  • 13
    Before trying this answer, definitely look at [Machavity's warning](http://stackoverflow.com/a/31058962/816458) and if you want the changes to persist, make sure to [use `global` in the command](http://stackoverflow.com/a/35018178/816458). – thomas88wp May 04 '16 at 13:58
  • 6
    Every time when I come back to MySql after some time, I always meet this problem which annoys me, because I always forget what is the problem :) The feeling is just disappointing, when you think that it was working and now it doesn't because of version change. – X-HuMan Jun 09 '16 at 13:33
  • Emptying out SQL mode should be fine for the current session, especially if you are using PHP where the mysql session ends after the script dies – Adam Fowler Oct 14 '16 at 17:54
  • before doing it, I recommend seeing this stackoverflow.com/a/38551525/3160597 – azerafati Aug 12 '17 at 15:33
  • Can't we change this from "my.cnf" file? – oralunal Aug 29 '17 at 17:36
  • Using Laravel 5.4: DB::statement('SET sql_mode = \'\''); – Edmunds22 Sep 06 '17 at 07:37
  • 1
    But this disable all sql modes? – Preshan Pradeepa Oct 13 '17 at 05:59
116

Adding only one mode to sql_mode without removing existing ones:

SET sql_mode=(SELECT CONCAT(@@sql_mode,',<mode_to_add>'));

Removing only a specific mode from sql_mode without removing others:

SET sql_mode=(SELECT REPLACE(@@sql_mode,'<mode_to_remove>',''));

In your case, if you want to remove only ONLY_FULL_GROUP_BY mode, then use below command:

SET sql_mode=(SELECT REPLACE(@@sql_mode, 'ONLY_FULL_GROUP_BY', ''));

Reference: http://johnemb.blogspot.com/2014/09/adding-or-removing-individual-sql-modes.html

Janaka R Rajapaksha
  • 3,585
  • 1
  • 25
  • 28
59

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

Waqleh
  • 9,741
  • 8
  • 65
  • 103
53

Thanks to @cwhisperer. I had the same issue with Doctrine in a Symfony app. I just added the option to my config.yml:

doctrine:
    dbal:
        driver:   pdo_mysql
        options:
            # PDO::MYSQL_ATTR_INIT_COMMAND
            1002: "SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))"

This worked fine for me.

Arvid
  • 1,021
  • 2
  • 17
  • 25
  • 2
    And if need to combine with SET NAMES 'utf8' use following "SET NAMES 'utf8', sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));". If two queries are used instead like "SET NAMES 'utf8'; SET sql_mod..." it will throw "General error: 2014 Cannot execute queries while other unbuffered queries are active." – Ventzy Kunev Aug 03 '17 at 10:20
  • @VentzyKunev please do not follow this advice and do not set `SET NAMES` using this method, in most cases it is not needed symfony already set's it via doctrine.dbal.charset cofnig: https://symfony.com/doc/current/reference/configuration/doctrine.html , and does it properly via PDO dns, SET NAMES is outdated way of doing that, that should not be used for PHP version greater than 5.3 – LPodolski Jun 05 '19 at 11:31
46

On:

  • Ubuntu 14.04
  • mysql Ver 14.14 Distrib 5.7.16, for Linux (x86_64) using EditLine wrapper

Do:

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

Copy and paste:

[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

To the bottom of the file

$ sudo service mysql restart
Jadeye
  • 3,551
  • 4
  • 47
  • 63
  • Will the mysql.cnf never be overwritten by a mysql update? – cwhisperer Nov 08 '16 at 12:00
  • 1
    @cwhisperer `/etc/mysql/mysql.cnf` points to 2 config folders `!includedir /etc/mysql/conf.d/` + `!includedir /etc/mysql/mysql.conf.d/`. Same goes for `/etc/mysql/my.cnf`. Hence I assume that configurations files are not overridden upon update. You can read more here `http://dev.mysql.com/doc/mysql/en/server-system-variables.html` – Jadeye Nov 08 '16 at 12:07
  • I tried this and it didn't work on Ubuntu 18.04.2 bionic. I followed this and it worked: https://www.sitepoint.com/quick-tip-how-to-permanently-change-sql-mode-in-mysql/ - maybe it is important to use this format with spaces and quotes: `sql_mode = "STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"` maybe it is important to create a new file `/etc/mysql/mysql.conf.d/mysqld_mode.cnf` instead – rubo77 Mar 29 '19 at 05:38
29

Add or Remove modes to sql_mode

MySQL 5.7.9 or later

To add or remove a mode from sql_mode, you can use list_add and list_drop functions.

To remove a mode from the current SESSION.sql_mode, you can use one of the following:

SET SESSION sql_mode = sys.list_drop(@@SESSION.sql_mode, 'ONLY_FULL_GROUP_BY');
SET sql_mode = sys.list_drop(@@sql_mode, 'ONLY_FULL_GROUP_BY');
SET @@sql_mode = sys.list_drop(@@sql_mode, 'ONLY_FULL_GROUP_BY');

To remove a mode from the GLOBAL.sql_mode that persists for the current runtime operation, until the service is restarted.

SET GLOBAL sql_mode = sys.list_drop(@@GLOBAL.sql_mode, 'ONLY_FULL_GROUP_BY');

MySQL 5.7.8 or prior

Since the sql_mode value is a CSV string of modes, you would need to ensure that the string does not contain residual commas, which can be accomplished by using TRIM(BOTH ',' FROM ...).

To remove a mode from the sql_mode variable, you would want to use REPLACE() along with TRIM() to ensure any residual commas are removed.

SET SESSION sql_mode = TRIM(BOTH ',' FROM REPLACE(@@SESSION.sql_mode, 'ONLY_FULL_GROUP_BY', ''));
SET GLOBAL sql_mode = TRIM(BOTH ',' FROM REPLACE(@@GLOBAL.sql_mode, 'ONLY_FULL_GROUP_BY', ''));

To add a mode to the sql_mode variable, you would want to use CONCAT_WS(',', ...), to ensure a comma is appended with the current modes and TRIM() to ensure any residual commas are removed.

SET SESSION sql_mode = TRIM(BOTH ',' FROM CONCAT_WS(',', 'ONLY_FULL_GROUP_BY', @@SESSION.sql_mode));
SET GLOBAL sql_mode = TRIM(BOTH ',' FROM CONCAT_WS(',', 'ONLY_FULL_GROUP_BY', @@GLOBAL.sql_mode));

NOTE: Changing the GLOBAL variable does not propagate to the SESSION variable, until a new connection is established.

The GLOBAL variable will persist until the running service is restarted.

The SESSION variable will persist for the current connection, until the connection is closed and a new connection is established.


Revert to GLOBAL.sql_mode

Since SET sql_mode = 'ONLY_FULL_GROUP_BY'; was executed without the GLOBAL modifier, the change only affected the current SESSION state value, which also pertains to @@sql_mode. To remove it and revert to the global default on server restart value, you would want to use the value from @@GLOBAL.sql_mode. [sic]

The current SESSION value is only valid for the current connection. Reconnecting to the server will revert the value back to the GLOBAL value.

To revert the current session state value to the current global value, you can use one of the following:

SET SESSION sql_mode = @@GLOBAL.sql_mode;
SET @@sql_mode = @@GLOBAL.sql_mode;
SET sql_mode = @@GLOBAL.sql_mode;

Change SESSION.sql_mode value to ONLY_FULL_GROUP_BY

SET sql_mode = 'ONLY_FULL_GROUP_BY';
SELECT @@sql_mode, @@GLOBAL.sql_mode;
+--------------------+----------------------------------------------+
| @@sql_mode         | @@GLOBAL.sql_mode                            |
+--------------------+----------------------------------------------+
| ONLY_FULL_GROUP_BY | NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION |
+--------------------+----------------------------------------------+

Revert the SESSION.sql_mode value to the GLOBAL.sql_mode value

SET sql_mode = @@GLOBAL.sql_mode;
SELECT @@sql_mode, @@GLOBAL.sql_mode;
+----------------------------------------------+----------------------------------------------+
| @@sql_mode                                   | @@GLOBAL.sql_mode                            |
+----------------------------------------------+----------------------------------------------+
| NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION | NO_AUTO_VALUE_ON_ZERO,NO_ENGINE_SUBSTITUTION |
+----------------------------------------------+----------------------------------------------+

Server Restart Persistent sql_mode using the option file

To set the SQL mode at server startup, use the --sql-mode="modes" option on the command line, or sql-mode="modes" in an option file such as my.cnf (Unix operating systems) or my.ini (Windows). [sic]

Please see your version of MySQL to determine the supported and default modes.

MySQL >= 5.7.5, <= 5.7.6 default

[mysqld]
    
sql-mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"

Please see the Option File Syntax for more information.

The syntax for specifying options in an option file is similar to command-line syntax. However, in an option file, you omit the leading two dashes from the option name and you specify only one option per line. For example, --quick and --host=localhost on the command line should be specified as quick and host=localhost on separate lines in an option file. To specify an option of the form --loose-opt_name in an option file, write it as loose-opt_name.

The value optionally can be enclosed within single quotation marks or double quotation marks, which is useful if the value contains a # comment character.

Default sql_mode values

Since the MySQL documentation per-version values have been removed, I have added them here for your reference.

MySQL >= 8.0.11 8.0.5 - 8.0.10 Skipped

ONLY_FULL_GROUP_BY STRICT_TRANS_TABLES NO_ZERO_IN_DATE NO_ZERO_DATE ERROR_FOR_DIVISION_BY_ZERO NO_ENGINE_SUBSTITUTION

MySQL >= 5.7.8, <= 8.0.4

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

MySQL 5.7.7

ONLY_FULL_GROUP_BY STRICT_TRANS_TABLES NO_AUTO_CREATE_USER NO_ENGINE_SUBSTITUTION

MySQL >= 5.7.5, <= 5.7.6

ONLY_FULL_GROUP_BY STRICT_TRANS_TABLES NO_ENGINE_SUBSTITUTION

MySQL >= 5.6.6, <= 5.7.4

NO_ENGINE_SUBSTITUTION

MySQL <= 5.6.5

''
Will B.
  • 17,883
  • 4
  • 67
  • 69
  • 1
    At least for MySQL 8, setting in my.cnf requires two changes: the variable name has an underscore and the settings list is comma separated. Eg: [mysqld] sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION" – Mark Rogers Jul 05 '20 at 07:58
  • 1
    As mentioned in the answer, the listed sql_mode values were copied as displayed on the MySQL website, which can be seen by clicking the `[sic]` links. When setting sql_mode within the [option file (my.cnf)](https://dev.mysql.com/doc/refman/8.0/en/sql-mode.html#sql-mode-setting) the manual states that you should remove the leading two dashes of the command-line variable `--sql-mode=` in favor of using `sql-mode=`, https://dev.mysql.com/doc/refman/8.0/en/option-files.html#option-file-syntax however either syntax works currently. Lastly quotes are not required to wrap the sql_mode values. – Will B. Jul 05 '20 at 15:09
28

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.

Community
  • 1
  • 1
br3nt
  • 9,017
  • 3
  • 42
  • 63
21

As of MySQL 5.7.x, the default sql mode includes ONLY_FULL_GROUP_BY.

(Before 5.7.5, MySQL does not detect functional dependency and ONLY_FULL_GROUP_BY is not enabled by default).

ONLY_FULL_GROUP_BY: Non-deterministic grouping queries will be rejected

For more details check the documentation of sql_mode

You can follow either of the below methods to modify the sql_mode

Method 1:

Check default value of sql_mode:

SELECT @@sql_mode

Remove ONLY_FULL_GROUP_BY from console by executing below query:

SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

Method 2:

Access phpmyadmin for editing your sql_mode

  • Login on phpmyadmin and open localhost
  • Top on Variables present on the top in menu items and search out for sql mode
  • Click on edit button to remove ONLY_FULL_GROUP_BY and save sql mode settings in phpmyadmin

Restart MySQL server

 sudo service mysql restart

OR

Logout phpmyadmin and login again.

Ankit Jindal
  • 3,672
  • 3
  • 25
  • 37
20

To disable ONLY_FULL_GROUP_BY with the help of the following query.

SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

And to enable the ONLY_FULL_GROUP_BY use following query.

SET sql_mode = 'ONLY_FULL_GROUP_BY';
Nilesh Patil
  • 41
  • 1
  • 2
18

If you are using WAMP. Left click on the WAMP icon then goto MySQL -> MySQL settings -> sql-mode and then select sql-mode->user mode

Checkout this image

thor
  • 21,418
  • 31
  • 87
  • 173
Shiran Gabriel
  • 440
  • 4
  • 15
  • Is there a reason that I don't have MySQL Settings in my WAMP install? There is Service administration and MySQL console but no settings? – GiarcTNA Jan 18 '17 at 06:51
  • This is exactly what I was looking for! Thanks for providing a simple WAMP Server solution! I needed this while trying to do #aggregation in this tutorial: https://youtu.be/HXV3zeQKqGY?t=9718 – Eric Hepperle - CodeSlayer2010 Dec 05 '18 at 16:11
17

This is what I performed to fix on Mysql workbench:

Before I got the current value with the below command

SELECT @@sql_mode 

later I removed the ONLY_FULL_GROUP_BY key from the list and I pasted the below command

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'
Matt Vegas
  • 453
  • 5
  • 17
  • NOTE: changing the sql_mode will not affect stored procedures. So you need to drop and execute SP again to take affect – Abeer Sul Jan 10 '21 at 21:37
15

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!

Alexandre Ribeiro
  • 1,384
  • 1
  • 13
  • 19
  • 2
    I would strongly recommend the aforementioned approach than setting it on the session, thanks to @alexandre-ribeiro. For those who have Ubuntu 16.04 and mysql 5.7.x, better edit the file and enter the _ini_ directive *sql_mode=* under *[mysqld]* group, as declaring against *[mysql]* does not work, as per my experience. – codarrior Sep 18 '17 at 04:07
  • I have MySQL 5.7.22. It's strange, but I had to remove **both** STRICT_TRANS_TABLES and ONLY_FULL_GROUP_BY from the sql_mode declaration in my.cnf, as shown above, for this to work. In reality, I only want to remove the ONLY_FULL_GROUP_BY mode. If I do "set global/session sql_mode = ..." I can remove just ONLY_FULL_GROUP_BY without having to remove STRICT_TRANS_TABLES for it to work. But since this doesn't survive restarts, so it's not much use to me. – RayCh Jun 11 '18 at 10:28
12

If you are using MySQL 8.0.11 so, you need to remove the ’NO_AUTO_CREATE_USER‘ from sql-mode.

Add following line in file /etc/mysql/my.cnf and [mysqld] header

[mysqld]

sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
Hiren Bhut
  • 1,166
  • 1
  • 13
  • 19
12

For Mac OS Mojave (10.14) Open terminal

$ sudo mkdir /usr/local/mysql-5.7.24-macos10.14-x86_64/etc
$ cd /usr/local/mysql-5.7.24-macos10.14-x86_64/etc
$ sudo nano my.cnf

Paste following:

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

Shortkeys to Save & Exit nano: Ctrl+x and y and Enter

Note: You might need to update mysql-5.7.24-macos10.14-x86_64 in these commands, just check the correct folder name you got within /usr/local/

Hope it will help someone!

AamirR
  • 11,672
  • 4
  • 59
  • 73
12
  1. Check default value of sql_mode:

    SELECT @@sql_mode;

  2. Remove ONLY_FULL_GROUP_BY from console by executing below query:

SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

  1. Also remove it from your specific Database

use database_name;

SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

  1. Restart your web app server

  2. Access that page that was causing this issue. It would work now.

OR

  1. Add following in your my.cnf file

    sql_mode="TRADITIONAL"

Note: if you are using mac my.cnf might be available here /usr/local/etc/my.cnf

Or try this link https://dev.mysql.com/doc/refman/8.0/en/option-files.html

  1. Restart MySQL server

    sudo /usr/local/bin/mysql.server restart

    OR

    brew services restart mysql

Taimoor Changaiz
  • 10,250
  • 4
  • 49
  • 53
11

On my sql (version 5.7.11 running on Mac OS X) this work for me on mysql shell client:

SET
@@GLOBAL.sql_mode="STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

According to MySQL 5.6 Documentation, sql_mode is default is

blank string in MySQL 5.6.5 and back NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES in 5.6.6 +

mysql 5.6 reference

8

This worked for me:

SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));
informer
  • 821
  • 6
  • 18
7

I'm using doctrine and I have added the driverOptions in my doctrine.local.php :

return array(
'doctrine' => array(
    'connection' => array(
        'orm_default' => array(
            'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
            'params' => array(
                'host' => 'localhost',
                'port' => '3306',
                'user' => 'myusr',
                'password' => 'mypwd',
                'dbname' => 'mydb',
                'driverOptions' => array(
                    PDO::MYSQL_ATTR_INIT_COMMAND => "SET sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))"
                ),
            ),
        ),
    ),
));

In phpmyadmin the user needs SUPER activated in the privileges.

cwhisperer
  • 1,478
  • 1
  • 32
  • 63
  • 3
    Using the yaml notation for configuring Doctrine (as done in Symfony) you need to use "1002" instead of the constant "PDO::MYSQL_ATTR_INIT_COMMAND", but nevertheless this is what I have been looking for a few weeks ago and couldn't find out. Thanks for your solution! Worked for me. – Arvid Nov 07 '16 at 14:20
6

Add the line

sql-mode=""

in my.ini file as a permanent fix.

Mathew Dony
  • 376
  • 4
  • 11
  • If we set `sql-mode` as empty, won't it affect other things. We generally just remove `ONLY_FULL_GROUP_BY` from `sql_mode` – Ankit Jindal Jul 29 '22 at 18:09
5

To whom is running a VPS/Server with cPanel/WHM, you can do the following to permanently disable ONLY_FULL_GROUP_BY

You need root access (either on a VPS or a dedicated server)

  1. Enter WHM as root and run phpMyAdmin

  2. Click on Variables, look for sql_mode, click on 'Edit' and copy the entire line inside that textbox

e.g. copy this:

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. Connect to you server via SFTP - SSH (root) and download the file /etc/my.cnf

  2. Open with a text editor my.cnf file on your local PC and paste into it (under [mysqld] section) the entire line you copied at step (2) but remove ONLY_FULL_GROUP_BY,

e.g. paste this:

# disabling ONLY_FULL_GROUP_BY
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. Save the my.cnf file and upload it back into /etc/

  2. Enter WHM and go to "WHM > Restart Services > SQL Server (MySQL)" and restart the service

Marco Demaio
  • 33,578
  • 33
  • 128
  • 159
5

Im working with mysql and registered with root user, the solution that work for me is the following:

mysql > SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));

Jorge Santos Neill
  • 1,635
  • 13
  • 6
3

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.

demisx
  • 7,217
  • 4
  • 45
  • 43
3

The best is to try to use ONLY_FULL_GROUP_BY on new projects while remaining backward compatible on existing sites and databases. For this I opted for a modification of the SQL Mode when loading mysqli, respectively PDO in my classes.

For mysqli :

mysqli_query($this->link,"SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))");

For PDO class :

PDO::MYSQL_ATTR_INIT_COMMAND => "SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))"

Example with PDO init :

try {
    $dns     = 'mysql:host=localhost;dbname=' . $prod_db;
    $user    = _DBUSER_;
    $pass    = _DBPASS_;
    $options = array(
        PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
        PDO::MYSQL_ATTR_INIT_COMMAND => "SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''))"
    );

    $db = new PDO($dns, $user, $pass, $options);
} 

catch(Exception $e) {
    mail("contact@xxxxxx.xx","Database Error ",$dns.",".$user);
    echo "Unable ot connect to mySQL : ", $e->getMessage();
    die();
} 

Thus, the new classes created on the same server will work with new standard of databases.

Meloman
  • 3,558
  • 3
  • 41
  • 51
2

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"
Dio Phung
  • 5,944
  • 5
  • 37
  • 55
2

Here is my solution changing the Mysql configuration through the phpmyadmin dashboard:

In order to fix "this is incompatible with sql_mode=only_full_group_by": Open phpmyadmin and goto Home Page and select 'Variables' submenu. Scroll down to find sql mode. Edit sql mode and remove 'ONLY_FULL_GROUP_BY' Save it.

Marcello Perri
  • 572
  • 7
  • 22
2

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"

Then restart mysql by running this sudo service mysql restart

Azam Alvi
  • 6,918
  • 8
  • 62
  • 89
1

What about "optimizer hints" from MySQL 8.x ?

for example:

SELECT /*+ SET_VAR(sql_mode='STRICT_TRANS_TABLES') */
... rest of query

more information: https://dev.mysql.com/doc/refman/8.0/en/optimizer-hints.html#optimizer-hints-set-var

Marek Lisiecki
  • 498
  • 6
  • 10
0

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'
Karthik
  • 317
  • 4
  • 17
0

One important thing to note, if you have ANSI on sql_mode:

Equivalent to REAL_AS_FLOAT, PIPES_AS_CONCAT, ANSI_QUOTES, IGNORE_SPACE, and (as of MySQL 5.7.5) ONLY_FULL_GROUP_BY.

See https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sqlmode_ansi

Marcelo Vani
  • 56
  • 1
  • 2
0

in case anyone using Drupal 8 face this issue with mysql 8, I fixed that by overriding the default configuration by adding this piece of code.

enter image description here

Source: https://www.drupal.org/project/drupal/issues/2856270

The option, just in case:

'init_commands' => array(
    'sql_mode' => "SET sql_mode =''"
  )
Naser Nikzad
  • 713
  • 12
  • 27
  • 1
    Leaving the sql_mode blank won't have any side effects? – Ahmad Karimi Dec 30 '20 at 07:33
  • @AhmadKarimi Maybe, so for those who are worried about this, here is another option they can set. 'sql_mode' => "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 |'" – Naser Nikzad Jan 14 '21 at 07:06
  • Remember to clear cache after this config change as well, drush cr – Naser Nikzad Aug 18 '21 at 05:42
  • In the early days MySQL had problems to detect functional dependencies with `GROUP BY`, so they just allowed any column in the `SELECT` clause regardless of what was in `GROUP BY`. Then they started fixing this and invented ONLY_FULL_GROUP_BY mode. And when they finally got it right, they made ONLY_FULL_GROUP_BY the default mode. So, do the problems with Drupal indicate that there are still edge cases where MySQL's functional dependencies detection fails or is Drupal buggy? – Thorsten Kettner Aug 19 '21 at 12:18
0

In case someone else facing same issue as me. On Ubuntu 16.04, the only persistent solution it worked for me:

Edit /lib/systemd/system/mysql.service and set it to:

[Unit]
Description=MySQL Community Server
After=network.target

[Install]
WantedBy=multi-user.target

[Service]
User=mysql
Group=mysql
PermissionsStartOnly=true
ExecStartPre=/usr/share/mysql/mysql-systemd-start pre
# Normally, we'd simply use:
# ExecStart=/usr/sbin/mysqld
ExecStart=/usr/sbin/mysqld --sql-mode=ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
ExecStartPost=/usr/share/mysql/mysql-systemd-start post
TimeoutSec=600
Restart=on-failure
RuntimeDirectory=mysqld
RuntimeDirectoryMode=755`
fgonzalez
  • 3,787
  • 7
  • 45
  • 79
0

On Ubuntu Ubuntu 20.04.6 LTS

with mysql Ver 8.0.32-0ubuntu0.20.04.2 for Linux on x86_64 ((Ubuntu))

sudo -i
nano /etc/mysql/mysql.conf.d/mysql.cnf

# add the following after [mysqld]
sql_mode = "STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
# Ctrl-O to save, Ctrl-X to exit nano

# use systemctl to restart mysql
systemctl restart mysql

askme
  • 111
  • 1
  • 4
0

To permanently disable it in windows, navigate to C:\ProgramData\MySQL\MySQL Server (version no)/. Open my.ini file then find a line starting with sql-mode= delete the text "ONLY_FULL_GROUP_BY" then restart the MySQL service.

Albert Alberto
  • 801
  • 8
  • 15
0

I found this line by default in my.ini

 sql-mode="ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"

And removed ONLY_FULL_GROUP_BY,

DONT FORGET TO RESTART MYSQL: net stop [YOUR MYSQL NAME];net start [YOUR MYSQL NAME]

Jim VanPetten
  • 413
  • 3
  • 11