How to get rid of STRICT SQL mode in MySQL - mysql

This is a follow up to this question MYSQL incorrect DATETIME format
How to get rid of STRICT_TRANS_TABLES once and for all?
mysql --help reports the following configs:
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
$ ls /etc/my.cnf /etc/mysql/my.cnf /usr/local/etc/my.cnf ~/.my.cnf
ls: /Users/pain/.my.cnf: No such file or directory
ls: /etc/mysql/my.cnf: No such file or directory
ls: /usr/local/etc/my.cnf: No such file or directory
/etc/my.cnf
$ cat /etc/my.cnf
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION
But this doesn't help. I have some legacy code and each time I reboot the computer I have to launch mysql and change sql_mode.
Update
So I gave up on Homebrew-installed MySQL and downloaded it from from mysql.com. But that didn't help either. Following the answers here: How to fix `unknown variable 'sql-mode=ANSI'`? I have tried different variations of /etc/my.cnf: [mysql], [mysqld], sql_mode, sql-mode – nothing helped.

This problem scuppered me for a while as well. None of the answers so far addressed the original problem but I believe mine does so I'll post it in case it helps anyone else.
I have MySQL (from mysql.com) Community Edition 5.7.10 installed on OS X 10.10.3
In the end I created a /etc/mysql/my.cnf with the following contents:-
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION
After restarting the server a SHOW VARIABLES LIKE 'sql_mode'; gave me:-
+---------------+------------------------+
| Variable_name | Value |
+---------------+------------------------+
| sql_mode | NO_ENGINE_SUBSTITUTION |
+---------------+------------------------+
1 row in set (0.00 sec)
Finally, no strict mode!

So in the end I removed the MySQL Server I got from the mysql.com, reinstalled it via Homebrew and had to edit
/usr/local/Cellar/mysql/5.6.xx/my.cnf
Where I could comment out the darned STRICT_TRANS_TABLES.
However this doesn't explain why the default config overrides the one from /etc/my.cnf, but I spent too much time on this already as it is. And by the way I am still not sure what to do with the mysql.com provided distribution.

On Centos 6.5 i had to edit /usr/my.cnf
and set (even though /etc/my.cnf existed and bindings were successfully set there
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION
package was from:
mysql-community-client.x86_64 5.6.16-1.el6 #mysql56-community

According to MySQL Strict Mode on OS X the problematic setting is actually at /usr/local/mysql/my.cnf and can be commented out to stop this behavior.

Now you can`t set sql_mode to empty string, actual query is:
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 5.7.16

I tried every answer I could find on this issue using MySQL 5.7 on Mac OS 10.12 and ultimately got strict mode turned off not because of the location of my.cnf, which can presumably be in any of the places that MySQL says it checks, but thanks to a UNIX permissions issue.
I used MySQL Workbench 6.2.3.12313 to create my.cnf initially. This caused two possible problems: first, it set the option to "sql-mode" instead of "sql_mode", and it made the file (located in /etc) readable and writable only for root. MySQL does not run as root when you install it the way I did, from the binary package on the MySQL web site--it runs as _mysql. So the _mysql user needs to be able to read /etc/my.cnf, or wherever you put it. In order for that to work, you need to run:
sudo chmod o+r /etc/my.cnf
and for good measure you may also want to run:
sudo chmod g+r /etc/my.cnf
Then make sure to restart MySQL. (I have found that this works best through the System Preferences MySQL panel on Mac OS; using the command line is kind of messy and MySQL Workbench's functionality simply doesn't work.) So long as you have an sql_mode setting in my.cnf that does not involve strict mode, strict mode should be off.

On Mac OS X El Capitan i created a file .my.cnf in the user home dir and set the settings for mysql under [mysqld] and then restarted mysql. Worked fine!

Related

Painfully set the sql_mode for vtiger

I couldn't figure out what Vtiger was on about when it asked me to set the php.ini file to error_reporting. Even after the error_reporting had been edited to show;
error_reporting = E_WARNING & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT
The CRM still persists in telling me it requires resetting, no matter how many time I restarted apache with sudo apachectl restart
Anyway...
After moving on, I managed to get to add the database, which at first, looks straight forward, but beware! There's one more huddle to get over before you can successfully install.
You'll probably receive the command to add:
sql_mode = ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Big headache!!
firstly, Mac OS X 10.13.* running MySQL mysql-5.7.21-macos10.13-x86_64 doesn't own /my.cnf and if like me, you're MySQL file will probably be stored in usr/local/mysql/bin/.
Stop looking, you wont find it anywhere on your Mac...
But there is light at the end of this tunnel...
start up terminal and type:
sudo pico /etc/my.cnf
My.cnf will be empty. Copy and paste this in the file:
[mysqld]
sql_mode = ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Save it (ctrl-x and hit y to accept saving the file) and exit, back into terminal.
Type:
sudo touch /etc/my.cnf
Then run mysql; mysql -u root -p
and check the entry,
SHOW VARIABLES LIKE 'sql_mode';
The result should show the settings you added to my.cnf
Now return to vtiger and continue the installation and it should work :)
For Ubuntu - Run command:
sudo nano /etc/mysql/my.cnf
Add the following part to the bottom:
[mysqld]
sql_mode=ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Run command to restart MySQL Service:
sudo service mysql restart
You will also need to change Database Collation to utf8_general_ci in phpmyadmin.
Done !
If you use mysql on windows, please edit file [mysql.ini]
(sample: C:\wamp64\bin\mysql\mysql5.7.21\mysql.ini) and add below info and then restart mysql service. It's OK
[mysqld]
sql_mode = ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
Quick & Dirty:
edit /modules/Install/Utils.php
Block: * Function to check sql_mode configuration
Line 349: return false;
change false to true
YOU DISALBE THE CHECK - OWN RISK
Vtiger CRM 7.3.0
[Windows Manual Installations]
Find My.ini in C:\ProgramData\MySQL\MySQL Server 8.0
Replace
sql-mode="ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION"
note: MySQL 8.0 does not support NO_AUTO_CREATE_USER (So remove it or sql service would not start)
Fire this query through the root user in MySQL
SET GLOBAL sql_mode = 'ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
And check if the settings are applied by firing the query as follows
SHOW GLOBAL VARIABLES LIKE 'sql_mode';
You basically have to disable it in utils.php as mysql 8.0 doesnt support NO_AUTO_CREATE_USER.

How to turn on/off MySQL strict mode in localhost (xampp)?

I want to know how to check whether MySQL strict mode is on or off in localhost(xampp).
If on then for what modes and how to off.
If off then how to on.
I already followed http://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-full and https://mariadb.com/kb/en/mariadb/sql_mode/ and other related sites too. But I didn't get an exact answer for my question.
->STRICT_TRANS_TABLES is responsible for setting MySQL strict mode.
->To check whether strict mode is enabled or not run the below sql:
SHOW VARIABLES LIKE 'sql_mode';
If one of the value is STRICT_TRANS_TABLES, then strict mode is enabled, else not.
In my case it gave
+--------------+------------------------------------------+
|Variable_name |Value |
+--------------+------------------------------------------+
|sql_mode |STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION|
+--------------+------------------------------------------+
Hence strict mode is enabled in my case as one of the value is STRICT_TRANS_TABLES.
->To disable strict mode run the below sql:
set global sql_mode='';
[or any mode except STRICT_TRANS_TABLES. Ex: set global sql_mode='NO_ENGINE_SUBSTITUTION';]
->To again enable strict mode run the below sql:
set global sql_mode='STRICT_TRANS_TABLES';
To Change it permanently in ubuntu do the following
in the ubuntu command line
sudo nano /etc/mysql/my.cnf
Then add the following
[mysqld]
sql_mode=
First, check whether the strict mode is enabled or not in mysql using:
SHOW VARIABLES LIKE 'sql_mode';
If you want to disable it:
SET sql_mode = '';
or any other mode can be set except the following.
To enable strict mode:
SET sql_mode = 'STRICT_TRANS_TABLES';
You can check the result from the first mysql query.
Check the value with
SELECT ##GLOBAL.sql_mode;
then clear the ##global.sql_mode by using this command:
SET ##GLOBAL.sql_mode=''
To change it permanently in Windows (10), edit the my.ini file. To find the my.ini file, look at the path in the Windows server. E.g. for my MySQL 5.7 instance, the service is MYSQL57, and in this service's properties the Path to executable is:
"C:\Program Files\MySQL\MySQL Server 5.7\bin\mysqld.exe" --defaults-file="C:\ProgramData\MySQL\MySQL Server 5.7\my.ini" MySQL57
I.e. edit the my.ini file in C:\ProgramData\MySQL\MySQL Server 5.7\. Note that C:\ProgramData\ is a hidden folder in Windows (10). My file has the following lines of interest:
# Set the SQL mode to strict
sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
Remove STRICT_TRANS_TABLES, from this sql-mode line, save the file and restart the MYSQL57 service. Verify the result by executing SHOW VARIABLES LIKE 'sql_mode'; in a (new) MySQL Command Line Client window.
(I found the other answers and documents on the web useful, but none of them seem to tell you where to find the my.ini file in Windows.)
In my case, I need to add:
sql_mode="STRICT_TRANS_TABLES"
under [mysqld] in the file my.ini located in C:\xampp\mysql\bin.
You can check the local and global value of it with:
SELECT ##SQL_MODE, ##GLOBAL.SQL_MODE;
I want to know how to check whether MySQL strict mode is on or off in
localhost(xampp).
SHOW VARIABLES LIKE 'sql_mode';
If result has "STRICT_TRANS_TABLES", then it's ON. Otherwise, it's OFF.
If on then for what modes and how to off.
If off then how to on.
For Windows,
Go to C:\Program Files\MariaDB XX.X\data
Open the my.ini file.
*On the line with "sql_mode", modify the value to turn strict mode ON/OFF.
Save the file
**Restart the MySQL service
Run SHOW VARIABLES LIKE 'sql_mode' again to see if it worked;
*3.a. To turn it ON, add STRICT_TRANS_TABLES on that line like this: sql_mode=STRICT_TRANS_TABLES. *If there are other values already, add a comma after this then join with the rest of the value.
*3.b. To turn it OFF, simply remove STRICT_TRANS_TABLES from value. *Remove the additional comma too if there is one.
**6. To restart the MySQL service on your computer,
Open the Run command window (press WINDOWS + R button).
Type services.msc
Click OK
Right click on the Name MySQL
Click Restart
on Debian 10
I start mysql from ./opt/lampp/xampp start
I do strace ./opt/lampp/sbin/mysqld and see that my.cnf is there:
stat("/opt/lampp/etc/my.cnf", {st_mode=S_IFREG|0644, st_size=5050, ...}) = 0
openat(AT_FDCWD, "/opt/lampp/etc/my.cnf", O_RDONLY|O_CLOEXEC) = 3
hence, I add sql_mode config to /opt/lampp/etc/my.cnf instead of /etc/mysql/my.cnf
on server console:
$ mysql -u root -p -e "SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION';"
Today I was trying to set the sql_mode=TRADITIONAL permanently but all efforts were in vain not because there are wrong answers but due to the way xampp configured the mysqld startup script. Let me explain in detail.
Of course you all try our best before coming to SO, so do I. I followed the comments in A:\xampp\mysql\bin\my.ini (given below):
# You can copy this file to
# A:/xampp/mysql/bin/my.cnf to set global options,
# mysql-data-dir/my.cnf to set server-specific options (in this
# installation this directory is A:/xampp/mysql/data) or
# ~/.my.cnf to set user-specific options.
So I tried A:/xampp/mysql/bin/my.cnf, A:/xampp/mysql/data/my.cnf but it wasn't even reading those files. Hours wasted in creating .cnf files in above locations. Worst part was it wasn't even working if I edit those my.ini files (i.e A:/xampp/mysql/bin/my.ini and A:/xampp/mysql/data/my.ini)
Then I checked all the folders to know how that control panel works and found thta xampp uses the mysql_start.bat script to start the msql deamon. Here is the bat file contents:
#echo off
cd /D %~dp0
echo Diese Eingabeforderung nicht waehrend des Running beenden
echo Please dont close Window while MySQL is running
echo MySQL is trying to start
echo Please wait ...
echo MySQL is starting with mysql\bin\my.ini (console)
mysql\bin\mysqld --defaults-file=mysql\bin\my.ini --standalone
if errorlevel 1 goto error
goto finish
:error
echo.
echo MySQL konnte nicht gestartet werden
echo MySQL could not be started
pause
:finish
Here we can clearly see that it is explicitly using the argument --defaults-file to tell MySQL daemon from where to read the files. Now I hope you have plenty of ideas to fix this.
Note: I've already added A:/xampp/mysql/bin to my PATH.
Now we have several options as I've mentioned below:
Add the exact path to the --defaults-file (i.e. --defaults-file=mysql\bin\my.cnf)
You can just ommit the flag and let mysqld read from default locations (can see those using mysql --help) Now you've 2 options:
either edit those default my.ini files or
follow the comments to create my.cnf files according to your installation
directory.
I just deleted that --defaults-file flag and let it run with MySQL's default configuration instead of xampp's. By the was I also have to change A:\xampp\mysql\data\my.ini from this:
[mysqld]
datadir=C:/xampp/mysql/data
[client]
to
[mysqld]
datadir=A:\xampp\mysql\data
[client]
to update the data directory. After that I just created a my.conf file in A:\xampp\mysql\data (data dir). with sql_mode option in it. It also worked with my.cnf in the A:\xampp\mysql\bin.
I have attached some screenshots for better understanding:
Updated data dir in A:\xampp\mysql\data\my.ini:
(option 1) Add my.cnf in A:\xampp\mysql\data:
(option 2) Add my.cnf in A:\xampp\mysql\bin:
You may found another solution too. Hope you are able to fix whatever issue you have regarding those config files.
For ubuntu :
Once you are connected to your VPS via SSH, please try connecting to your mysql with "root"
user: mysql -u root -p
Enter "root" user password and you will be in the mysql environment (mysql>), then simply check what is sql_mode, with the following command:
SHOW VARIABLES LIKE 'sql_mode';
Basically, you will see the table as your result, if the table has a value of STRICT_TRANS_TABLES, it means that this option is enabled, so you need to remove the value from this table with the following command:
set global sql_mode='';
This will set your table's value to empty and disable this setting. Like this:
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| sql_mode | |
+---------------+-------+
Please make sure to perform these commands within the MySQL environment and not simply via SSH. I think this moment was missed in the article provided below and the author assumes that the reader understands it intuitively.

cannot find mysql slow query log file on mac

I am trying to enable slow_query_log on mysql, but I could not find it on my mac.
I read in MySQL 5.7 Documentation that"
By default, the server writes files for all enabled logs in the data directory.
When I write show variables like '%slow_query%'; in mysql shell, I see the following:
but I can't see McBook-Pro-6-slow.log in the data directory. Here is all I can see in the data directory:
Could someone let me know why I can't see the slow log file?
In order to enable the slow_query_log, I've read here that I should add slow-query-log=1 to my.cnf. Here, my problem is that I am not sure where is mysql config file on my Mac. I've found a my-default.cnf in usr/local/mysql/support-files/ and another my.cnf file in /etc. Which one should I modify??
Thanks,
Refer to this Stackoverflow question MySQL 'my.cnf' location? which pertains to Mac OS. As you can see the permutations of locations are numerous usually compounded by different distros and MAMP XAMP WAMP bundles and Home Brew. It is not uncommon to have 2 mysql daemons on a box and not even know it.
Which is why in comments I suggested looking at the output of select ##basedir for the location of the my.ini (Windows) or my.cnf (Linux/Mac). That is not to suggest a configuration file is going to be there, but that is where it should be if one were to exist. Without it, baked-in default values are used. Often there is a stub, a suggested file, named differently (like my-default), awaiting your tweaks and a rename or copy to the appropriate file name of my.ini or my.cnf.
There is also a system variable named slow_query_log_file and its value visible if set thru SELECT ##slow_query_log_file;. For me right now it has a value of GUYSMILEY-slow.log because I did not set it in my ini (Windows) and it defaults to computername+"-slow.log".
That is the filename without the path. Where the file actually is written to is in the datadir seen with the output of select ##datadir;.
On my system this means (via ##basedir)
C:\Program Files\MySQL\MySQL Server 5.6\my.ini
would have a setting that ends up in a slowlog file written to in this absolute path (helped by ##datadir):
C:\ProgramData\MySQL\MySQL Server 5.6\data\GUYSMILEY-slow.log
and a fragment inside that log file might show something like this:
Ini and cnf changes require a MySQL daemon restart. In that configuration file a section similar to (my 5.6)
[mysqld]
basedir=C:\\Program Files\\MySQL\\MySQL Server 5.6\\
datadir=C:\\ProgramData\\MySQL\\MySQL Server 5.6\\Data\\
port=3306
log_warnings = 2
and (my 5.7)
[mysqld]
basedir=C:\\Program Files\\MySQL\\MySQL Server 5.7\\
datadir=C:\\ProgramData\\MySQL\\MySQL Server 5.7\\Data\\
port=3307
log_error_verbosity=2
the above is used within the [mysqld] section to play with settings. What I suggest is playing with this section with an innocuous setting like log_error_verbosity (5.7.2 and up) or similar, save it. Restart the deamon and determine if the variable (as Rick James would call settings because most really aren't dynamically settable). So a sanity check of select ##log_error_verbosity (5.7.2 and up) can confirm it the change is picked up. If it is, bingo, you are doing it right.
The Manual Page Server System Variables depicts the variables (settings) and whether or not they can be dynamically set/changed after the config file load via commands. Dynamic changes are reverted upon daemon restart.
How one would dynamically change a variable might look like:
SET GLOBAL log_error_verbosity=2;
Again, only certain variables are available in certain MySQL versions, such as the above, not available in older versions.
Also note multiple versions of MySQL running concurrently on a server. On mine i have 5.6.31 and 5.7.14. To access a different one via command line tools, use something like the -P 3307 switch to point at the one running on port 3307. Note the uppercase P as opposed to lowercase (which would mean prompt for password).
Determine if multiple instances are running. I use port checks such as
sudo netstat -tulpn (Linux)
netstat -aon | more (Windows, the top part, State=LISTENING)
Unfortunately these types of changes and trial and error take time and are very frustrating. Sorry I do not have a quick and easy answer for all cases.
Addendum
Notes here related to comments. In the below, w-x-y-z is a redacted IP Address.
On a Linux box (amazon ec2 redhat btw):
select ##slow_query_log;
-- 0 (so it is turned off)
SELECT ##slow_query_log_file;
-- /var/lib/mysql/ip-w-x-y-z-slow.log
select ##version;
-- 5.7.14
set global slow_query_log=1;
Error Code: 1227. Access denied; you need (at least one of) the SUPER privilege(s) for this operation 0.094 sec
(ok I was in MySQL Workbench as a dummied down user, off to do it as root via MySQL cmd line ...
mysql> set global slow_query_log=1;
Query OK, 0 rows affected (0.01 sec)
mysql> select ##slow_query_log;
+------------------+
| ##slow_query_log |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)
btw Workbench user can confirm the above `1`
at shell as linux user:
[ec2-user#ip-w-x-y-z ~]$ cd /var/lib/mysql
[ec2-user#ip-w-x-y-z mysql]$ sudo ls -la
(there were many files, only one needed to show you below)
-rw-r-----. 1 mysql mysql 179 Sep 19 01:47 ip-w-x-y-z-slow.log
[ec2-user#ip-w-x-y-z mysql]$ sudo vi ip-w-x-y-z-slow.log
(Header stub, the entire contents, no slow queries yet, log seen below):
/usr/sbin/mysqld, Version: 5.7.14 (MySQL Community Server (GPL)). started with:
Tcp port: 3306 Unix socket: /var/lib/mysql/mysql.sock
Time Id Command Argument
SHOW VARIABLES LIKE 'log_output'; to verify that it is set to FILE or FILE,TABLE.

Keep the show_compatibility_56 always ON in MySQL

I needed to set up the system variable "show_compatibility_56" to ON in MySQL. So, I run the command set global show_compatibility_56 = on;, and it worked However, I noticed that whenever I stop and then start the MySQL server, this variable goes back to OFF. Any hints on how to keep it always ON even if I restart the server?
I'm using a Laravel Homestead (Vagrant) box (MySql Ver 14.14 Distrib 5.7.17).
I needed to SSH into Homestead and then run:
echo "[mysqld]
show_compatibility_56 = ON
performance_schema" | sudo tee -a /etc/mysql/conf.d/mysql.cnf >/dev/null
sudo service mysql restart
(Thanks to Mark Reed for showing how to skip opening vim.)
Older version:
sudo vim /etc/mysql/conf.d/mysql.cnf
Then I added this section:
[mysqld]
show_compatibility_56 = ON
performance_schema
I was surprised that other answers here and elsewhere on the web didn't specify that it needed to be under [mysqld] instead of [mysql] and also that you must restart the MySql service:
sudo service mysql restart
you need to save this variable setting in your configuration file my.cnf for linux and my.ini for windows.
To make it permanent, you need to add this variable in configuration file of MySQL like we did for all other variables as:
show_compatibility_56 = ON
For Linux based system: File name is my.cnf and default location is /etc/my.cnf
For Windows based system: File name is my.ini and default location is your windows mysql data directory that you can check via below command:
show variables like 'datadir';
If you've installed MySQL through Hombrew on a Mac, there isn't a my.cnf by default. I created one in /etc/my.cnf, added the text from #Ryan's answer:
[mysqld]
show_compatibility_56 = ON
performance_schema
... and then restarted MySQL, with (I'm using the older 5.7 version):
$ brew services restart mysql#5.7
This worked for me.
As Zafar has already pointed you can set the variable in the configuration file to save the value.
Also note that this is now deprecated. The manual says:
Note:
show_compatibility_56 is deprecated because its only purpose is to
permit control over deprecated system and status variable information
sources that will be removed in a future MySQL release. When those
sources are removed, show_compatibility_56 will have no purpose and
will be removed as well.

How to make sql-mode="NO_ENGINE_SUBSTITUTION" permanent in MySQL my.cnf

UPDATE FIXED 1/18/15
After we recently updated to MySQL 5.6.27 (from the Ubuntu repo), this option now works. So this appears to have been a problem with the previous version of MySQL.
ORIGINAL QUESTION
With a new upgrade to MySQL (5.6.20), updates and inserts fail unless I set sql-mode to NO_ENGINE_SUBSTITUTION.
Thanks to the documentation, I can run the following from mysql terminal and that fixes the problem (temporarily):
SET GLOBAL sql_mode = 'NO_ENGINE_SUBSTITUTION';
SET SESSION sql_mode = 'NO_ENGINE_SUBSTITUTION';`
But the next time MySQL restarts, these settings are lost.
So I have tried to make that permanent by editing /etc/mysql/my.cnf (on my standard server running Ubuntu 12.04.5 LTS), and adding the config settings that the documentation says should be added:
[mysqld]
sql-mode="NO_ENGINE_SUBSTITUTION"
Alternative Syntaxes for Testing
Just for testing purposes, I have also tried the following formats (which do not cause errors when restarting MySQL, but they do not affect the setting).
# dash no quotes
sql-mode=NO_ENGINE_SUBSTITUTION
# underscore no quotes
sql_mode=NO_ENGINE_SUBSTITUTION
# underscore and quotes
sql_mode="NO_ENGINE_SUBSTITUTION"
Nothing works. After restart this setting is lost and I have to run the commands manually again from mysql terminal to make saving work again.
Alternative Locations
I know /etc/mysql/my.cnf is being referenced because we have replication defined in this file, and that is working.
There is not another identical setting in this file that is overwriting it.
I get a list of the config files that are being referenced by running this from the command line:
mysqld --help --verbose
I see a line that reads:
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf /usr/etc/my.cnf ~/.my.cnf
This is the default location it "looks" for files, it doesn't mean that it actually found a file there, e.g. my server doesn't have /etc/my.cnf, /usr/etc/my.cnf or ~/.my.cnf.
So it looks like my config in /etc/mysql/my.cnf is the only file mysql is referencing, and therefore this setting is not being overwritten.
Logical Conclusion of Testing
Logically then, it seems the syntax is not correct or is being ignored for some other reason. Any other ideas?
Just to add my configuration to the mix, I'm using MySQL 5.7.8 which has the same strict sql_mode rules by default.
I finally figured the following working in my /etc/mysql/my.conf:
[mysqld]
sql-mode="STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION"
i.e. dash, not underscore and quotes around the value.
I have NO other my.conf files other than /etc/mysql/my.conf
There are some extra config includes being loaded from /etc/mysql/conf.d/ but they are blank.
And that seems to work for me.
Your server may read a different my.cnf than the one you're editing (unless you specified it when starting mysqld).
From the MySQL Certification Study Guide:
The search order includes two general option files, /etc/my.cnf and
$MYSQL_HOME/my.cnf. The second file is used only if the MYSQL_HOME
environment variable is set. Typically, you seet it to the MySQL
installation directory. (The mysqld_safe script attempts to set
MYSQL_HOME if it is not set before starting the server.) The
option file search order also includes ~/.my.cnf (that is the home
directory). This isn't an especially suitable location for server
options. (Normally, you invoke the server as mysql, or as root
with a --user=mysql option. The user-specific file read by the
server would depend on which login account you invoke it from,
possibly leading to inconsistent sets of options being used.)
Another possibility is of course, that your sql-mode option gets overwritten further down in the same file. Multiple options have to be separated by , in the same line.
P.S.: And you need the quotes, IIRC. Now that you've tried it without quotes, I'm pretty sure, you're editing the wrong file, since MySQL doesn't start when there's an error in the option file.
P.P.S.: Had a look at my config files again, there it's
[mysqld]
sql_mode = "NO_ENGINE_SUBSTITUTION"
and it's working.
It should be:
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
instead of
[mysqld]
sql_mode="NO_ENGINE_SUBSTITUTION"
then restart mysqld service.
Woks fine for me on ubuntu 16.04.
path: /etc/mysql/mysql.cnf
and paste that
[mysqld]
#
# * Basic Settings
#
sql_mode = "NO_ENGINE_SUBSTITUTION"
For me it was a permission problem.
enter:
mysqld --verbose --help | grep -A 1 "Default options"
[Warning] World-writable config file '/etc/mysql/my.cnf' is ignored.
So try to execute the following, and then restart the server
chmod 644 '/etc/mysql/my.cnf'
It will give mysql access to read and write to the file.
On Linux Mint 18 the default config file that has the sql-mode option set is located here :
/usr/my.cnf
And relevant line is:
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
So You can set there.
If not sure what config file has such option You can search for it:
$ sudo find / -iname "*my.cnf*"
And get a list:
/var/lib/dpkg/alternatives/my.cnf
/usr/my.cnf
/etc/alternatives/my.cnf
/etc/mysql/my.cnf.fallback
/etc/mysql/my.cnf
My problem was that I had spaces in between the options on 5.7.20. Removing them so the line looked like
[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
The solution is pretty easy... Searched for it for a while and it turns out that you just have to edit 2 config-files:
/usr/my.cnf
/etc/mysql/my.cnf
in both files you'll have to add:
[mysqld]
...
sql_mode=NO_ENGINE_SUBSTITUTION
At least, that's what's working for 5.6.24-2+deb.sury.org~precise+2
For me both keys for sql-mode worked. Whether I used
# dash no quotes
sql-mode=NO_ENGINE_SUBSTITUTION
or
# underscore no quotes
sql_mode=NO_ENGINE_SUBSTITUTION
in the my.ini file made no difference and both were accepted, as far as I could test it.
What actually made a difference was a missing newline at the end of the my.ini file.
So everyone having problems with this or similar problems with my.ini/my.cnf: Make sure there is a blank line at the end of the file!
Tested using MySQL 5.7.27.
If you're using mariadb, you have to modify the mariadb.cnf file located in /etc/mysql/conf.d/.
I supposed the stuff is the same for any other my-sql based solutions.
I am running WHM 10.2.15-MariaDB. To permanently disable strict mode first find out which configuration file our installation prefers. For that, we need the binary’s location:
$ which mysqld
/usr/sbin/mysqld
Then, we use this path to execute the lookup:
$ /usr/sbin/mysqld --verbose --help | grep -A 1 "Default options"
Default options are read from the following files in the given order:
/etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
We can see that the first favored configuration file is one in the root of the etc folder but that there is a second .cnf file hidden - ~/.my.cnf. Adding the following to the ~/.my.cnf file permanently disabled strict mode for me (needs to be within the mysqld section):
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION
I found that adding the line to /etc/my.cnf had no effect at all apart from sending me crazy.
It was making me crazy also until I realized that the paragraph where the key must be is [mysqld] not [mysql]
So, for 10.3.22-MariaDB-1ubuntu1, my solution is, in /etc/mysql/conf.d/mysql.cnf
[mysqld]
sql_mode = "ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"
[Fixed]
Server version: 10.1.38-MariaDB - mariadb.org binary distribution
Go to: C:\xampp\mysql\bin
open my.ini in notepad and find [mysqld] (line number 27) then after this line(line no 28) just type: skip-grant-tables
save the file and then reload the phpmyadmin page.It worked for me.