Friday, July 11, 2014

Homebrew MariaDB (MySQL) and strict_all_tables

I recently updated my MariaDB on OSX using homebrew and suddenly my tests were failing with a mysql error for inserting nulls. After some quick research I found that in a recent update MySQL and MariaDB defaulted sql_mode to strict_all_tables. This prevents nulls from entering where they were allowed before.

Ideally that option is what you would want, but in our case our app has been running for years with NULLs everywhere. It would break our application and was in fact doing so in development.

After some reasearch I found that by putting

[mysqld]
sql_mode=""

would disable it globally but was insufficient because running

SELECT @@SESSION.sql_mode;

would return STRICT_ALL_TABLES. Meaning that the database was still not functioning as before.

There's probably a better way, but how I fixed it was to modify the plist.
~/Library/LaunchAgents/homebrew.mxcl.mariadb.plist
and added:

<string>--sql-mode=</string>

to the program parameters.

Edit: I finally figured out why that session was being set in my rails application by a default.

In your database.yml file you'll want to add strict: false

It just so happened that I had upgraded maria and rails at the same time. Leading me to have a false positive. The plist option only appeared to work. After running tests a few more times the tests were failing again.

No comments: