Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable STRICT_TRANS_TABLES for a Homebrew-installed MySQL server?

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!

like image 226
Adam Siler Avatar asked Dec 13 '13 22:12

Adam Siler


People also ask

What is Strict_trans_tables?

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.


2 Answers

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
like image 63
vd1008 Avatar answered Oct 31 '22 18:10

vd1008


@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?

like image 38
Adam Siler Avatar answered Oct 31 '22 17:10

Adam Siler