Running Rails 2 apps with modern MariaDB SQL server

Updated . Posted . Visible to the public.

You might have some trouble running a Rails LTS 2 app with MySQL 5.7.

If you don't want to hack Mysql 5.6 into your modern Ubuntu or use the MySQL sandbox, you might want to try MariaDB 10.x.

MariaDB 10.x should work with both old and new Rails applications.

Switch to MariaDB

Remove MySQL:

sudo apt remove mysql-common mysql-client mysql-server mysql-apt-config

Install MariaDB:

sudo apt install mariadb-server mariadb-client mariadb-common libmariadb2

You should now have MariaDB 10.x. Check with mysql --version.

You still need the MySQL development headers so you can build the mysql and mysql2 gems:

sudo apt install libmysqlclient-dev

Rebuild gems

The mysql and mysql2 gems installed on your machine are still built against the mysql-client package you just uninstalled, so you will probably get this error when booting your Rails app:

RuntimeError: Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (libmysqlclient.so.18: cannot open shared object file: No such file or directory - /home/henning/.rbenv/versions/2.3.5/lib/ruby/gems/2.3.0/gems/mysql2-0.2.24/lib/mysql2/mysql2.so)

You can fix this by re-installing the gems.

For every version of Ruby installed, remove the mysql and mysql2 gems:

gem uninstall --all mysql mysql2

The next time to work on a Rails project a bundle install will get you back the gems.

Run tests

Now run your test suite to see if the migration was successful.

Troubleshooting: Use an SQL compatibility mode

If you get unexpected SQL errors related to the handling of missing or invalid values, you need to either fix your app or remove the STRICT_TRANS_TABLES SQL mode flag that is default in MariaDB 10.2.

Note that if you switch to a more liberal SQL mode for your app, you must make sure that all developers, staging server and production server use the same SQL mode.

Henning Koch
Last edit
Michael Leimstädtner
License
Source code in this card is licensed under the MIT License.
Posted by Henning Koch to makandra dev (2018-03-13 15:02)