Question

MYSQL sql_mode Keeps reseting

Setup

mysql Ver 14.14 Distrib 5.7.38, for Linux (x86_64) using EditLine wrapper

Distributor ID: Ubuntu Description: Ubuntu 18.04.5 LTS Release: 18.04 Codename: bionic

MYSQL Keeps reseting my sql_mode and so my website is not working well.

The MySQL message is the following

Expression #18 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'testdevnew.f.created_at' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

What I do till now is from terminal to connect inside mysql with the command

mysql -u root -p

and run the following commands

mysql> set global sql_mode='NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

mysql> set session sql_mode='NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

And the error is gone, but for a couple of days… lets say that we restart mysql server and the above settings are gone.

Also tried to change the following files with the sql_mode that i would like to load after mysql restart.

File list

/etc/mysql/my.cnf

/etc/mysql/mysql.cnf

/etc/mysql/mysql.conf.d/mysqld.cnf

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

(I’ve also tried with value in quotes)

Then restart mysql

sudo service mysql restart

But the setting is not affecting mysql restart and I keep getting the error mentioned above.

mysqld --verbose --help

prints the following

sql-mode                                                     NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION


Any ideas of what am I doing wrong?


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

Hi there,

I’ve just tested this and it seems to be working well when the change is added to the /etc/mysql/mysql.conf.d/mysqld.cnf file under the [mysqld] section.

Do you see any errors in your MySQL error log that could indicate on what the issue might be?

  1. tail -100 /var/log/mysql/error.log

Also check for any other references of sql_mode:

grep -r sql_mode /etc/mysql/*

You might have to remove the duplicate ones.

Best,

Bobby