If you find yourself needing to add custom MySQL configuration there are several ways to do this.

The easiest way is to append the variables directly onto the my.cnf. This way you do not need to worry about if the setting already exists or has an existing value since MySQL will always take the last value.

before_script:
- echo -e "[server]\nwait_timeout=28800" | sudo tee -a /etc/mysql/my.cnf
- sudo service mysql restart

Or if you prefer to use a configuration file (smarter if you have more than one option). You can use the same method with a file like config/my.cnf:

[server]
wait_timeout=28800

Then:

before_script:
- cat "$TRAVIS_BUILD_DIR/config/my.cnf" | sudo tee -a /etc/mysql/my.cnf
- sudo service mysql restart

Note: It is not wise to take your whole my.cnf and replace the one on Travis. This will cause you grief. Rather only replace the values that you wish to be different on Travis.