Posted over 1 year ago. Visible to the public.

Running Rails 2 apps with modern MariaDB SQL server

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` ( 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/

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.

makandra has been working exclusively with Ruby on Rails since 2007. Our laser focus on a single technology has made us a leader in this space.

Owner of this card:

Henning Koch
Last edit:
6 months ago
by Henning Koch
About this deck:
We are makandra and do test-driven, agile Ruby on Rails software development.
License for source code
Posted by Henning Koch to makandra dev
This website uses cookies to improve usability and analyze traffic.
Accept or learn more