How to use MySQL in Gitlab CI

I am trying to run WordPress PHP unit tests on Gitlab CI.

I searched too much but I am not able to set up MySQL and create and use a database for testing. Can anybody show an example for this?

Example of .gitlab-ci.yml and commands to create database would be very helpful.

This is the test install script I will be using -

Hi @Nik have you seen http://doc.gitlab.com/ce/ci/languages/php.html ? I’d be glad to get some feedback.

Hey @axil, Thank you for the link, this helped me a lot.

I got CI up and running for PHP tests, but for WordPress tests I am still facing problems with MySql.

Is there a way I can test if MySql is working inside the CI enviornment? when I check mysql --version it fails with mysql: command not found

Can you post your current .gitlab-ci.yml?

Just as a note, because I was looking for an answer for a few hours. Usually, your image wont have mysql-client, so you cant connect to the service out of the box. It would be nice to have this kind of information anywhere in documentation, because its not really that obvious :wink:

Just install it:
apt-get --assume-yes install mysql-client

and then you can connect, remember the host is “mysql” not localhost
mysql -h mysql -u root -p somefancypassword

You could use the MySQL image?
https://hub.docker.com/_/mysql/

During the runner register you can say which image you want to use. Or you can define the image within the .gitlab-ci.yml file at the top of the file. Like so:

image: mysql:5.5

or atleast take a look at this docker file to create your own Docker image:

I install it via the gitlab-ci.yml