It seems that MySQL recently (5.6?) changed the default SQL mode to be more restrictive. The new mode is "STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION". I like the change, but at least one website that I maintain does not. INSERT queries are failing because they don't specify values for columns that don't have defaults. Before, MySQL would infer default values by column type.
For now, I want to disable STRICT_TRANS_TABLES. I have added sql_mode=NO_ENGINE_SUBSTITUTION
to my.cnf
and restarted the server but the strict setting persists. What am I doing wrong?
MySQL version:
$ mysqld --version
mysqld Ver 5.6.15 for osx10.9 on x86_64 (Homebrew)
my.cnf:
$ cat /etc/my.cnf
[mysqld]
sql_mode=NO_ENGINE_SUBSTITUTION
# not sure if this is needed but it doesn't seem to have an effect either way
[mysqld_safe]
sql_mode=NO_ENGINE_SUBSTITUTION
Confirm that mysqld would use settings in my.cnf:
$ mysqld --print-defaults
mysqld would have been started with the following arguments:
--sql_mode=NO_ENGINE_SUBSTITUTION
Confirm that mysqld is not currently running:
$ ps aux | grep mysql
metaphile 1022 0.0 0.0 2432784 600 s003 S+ 3:10PM 0:00.00 grep mysql
Property list provided by Homebrew:
$ cat ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>KeepAlive</key>
<true/>
<key>Label</key>
<string>homebrew.mxcl.mysql</string>
<key>ProgramArguments</key>
<array>
<string>/usr/local/opt/mysql/bin/mysqld_safe</string>
<string>--bind-address=127.0.0.1</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>WorkingDirectory</key>
<string>/usr/local/var</string>
</dict>
</plist>
Start MySQL and check SQL mode:
$ launchctl load -w ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist
$ mysql -uroot
...
mysql> SELECT @@GLOBAL.sql_mode, @@SESSION.sql_mode;
+--------------------------------------------+--------------------------------------------+
| @@GLOBAL.sql_mode | @@SESSION.sql_mode |
+--------------------------------------------+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+--------------------------------------------+
1 row in set (0.00 sec)
Argh!
For STRICT_TRANS_TABLES , MySQL converts an invalid value to the closest valid value for the column and inserts the adjusted value. If a value is missing, MySQL inserts the implicit default value for the column data type.
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
@ssnobody's answer prompted me to search my entire system for my.cnf files. I had already checked the locations listed by mysqld --help --verbose
. It turns out that my server is using /usr/local/Cellar/mysql/5.6.15/my.cnf
which I had wrongly assumed to be a sample file. The file is not symlinked from any of the standard locations, including /usr/local/mysql
.
Can anybody shed some light on this? Is it a Homebrew thing? How could I have figured this out except by making test modifications to every my.cnf that I could find?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With