【发布时间】:2014-01-01 20:04:45
【问题描述】:
似乎 MySQL 最近(5.6?)将默认 SQL 模式更改为更具限制性。新模式是“STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION”。我喜欢这种变化,但至少有一个我维护的网站不喜欢。 INSERT 查询失败,因为它们没有为没有默认值的列指定值。以前,MySQL 会根据列类型推断默认值。
现在,我想禁用 STRICT_TRANS_TABLES。我已将sql_mode=NO_ENGINE_SUBSTITUTION 添加到my.cnf 并重新启动服务器,但严格设置仍然存在。我做错了什么?
MySQL 版本:
$ mysqld --version
mysqld Ver 5.6.15 for osx10.9 on x86_64 (Homebrew)
我的.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
确认 mysqld 将使用 my.cnf 中的设置:
$ mysqld --print-defaults
mysqld would have been started with the following arguments:
--sql_mode=NO_ENGINE_SUBSTITUTION
确认mysqld当前没有运行:
$ ps aux | grep mysql
metaphile 1022 0.0 0.0 2432784 600 s003 S+ 3:10PM 0:00.00 grep mysql
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>
启动 MySQL 并检查 SQL 模式:
$ 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)
啊!
【问题讨论】: