Skip to Content

Custom MySQL configuration on Travis

Posted on

We ran into some character encoding issues with our automated tests on Travis recently. Luckily, it’s very easy to change the MySQL configuration in your test environment.

If you look at the default my.cnf configuration file in the sudo-enabled environment, you will see that it ends with a !includedir directive:

!includedir /etc/mysql/conf.d/

This directive will look for any .cnf file in /etc/mysql/conf.d/ and load it. It allows you to add new configuration values or overwrite existing ones. This keeps things nicely organised and easy to manage.

To make use of this option, you need to make sure that you are running Travis builds in a sudo-enabled environment. In your .travis.yml file:

sudo: required

Then, create the custom configuration file. I put it in _travis/mysql.cnf:

[mysqld]
collation-server=utf8_unicode_ci
character-set-server=utf8

Finally, move the config file to the right location and restart MySQL to pick up the changes before you run your tests. In .travis.yml:

before_install:
- sudo cp $TRAVIS_BUILD_DIR/_travis/mysql.cnf /etc/mysql/conf.d/
- sudo service mysql restart

That’s it: your Travis builds now runs with your custom MySQL configuration!

comments powered by Disqus