2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

MySQLのdatetimeに対して空白を挿入する方法

Last updated at Posted at 2014-10-30

今まで動いていたアプリケーションがサーバー移行後に動かなくなった。
データベース側でdatetimeに対して空白を挿入する際にエラーが出ている模様。

対処方法

sql_modeの設定が異なる事が原因でした。
sql_modeのSTRICT_TRANS_TABLESをはずせば、SQLが通ります。

古いサーバ

mysql> SELECT @@GLOBAL.sql_mode;
+-------------------+
| @@GLOBAL.sql_mode |
+-------------------+
|                   |
+-------------------+
1 row in set (0.00 sec)

新しいサーバ

mysql> SELECT @@GLOBAL.sql_mode;
+--------------------------------------------+
| @@GLOBAL.sql_mode                          |
+--------------------------------------------+
| STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+--------------------------------------------+

my.cnfを修正します。

sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
↓
sql_mode=''

以上

参考

MySQL5.6にしていくつかのSQLでエラーが出るようになった

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?