Running MySQL inside GitLab Runner


My goal is to run database tests inside the CI pipeline for my Node.js application. I imagine it being that when I push code, the .yml script tells the runner to create a database and then when npm test script is executed the database is already set up and waiting to be used for testing purposes. What I get instead is just mysql: command not found with the given .yml script. I did set up the environment variables in the settings already.
I am quite inexperienced with the whole GitLab Runner environment so any pointers or tips on how can I fix or solve my problem is highly appreciated.

image: node:latest

  - mysql:5.7

  # Configure mysql service (

  - install
  - db-setup
  - test

  stage: install
    - echo "NPM SET UP"
    - npm install

  stage: db-setup
    - echo "DB SET UP:"
    - mysql --user=root --password="$MYSQL_ROOT_PASSWORD" --host=mysql --execute "CREATE DATABASE "$MYSQL_DATABASE";"

  stage: test
    - echo "TEST RUN:"
    - npm test

Hi @bmorkunas

I’m assuming that you’re either using GitLab shared runners, or your own Docker runners?

I suspect your main problem here is that the node:latest image doesn’t come with a MySQL client. Can you try the config below and see if that gets you a bit closer?

Hi @snim2,

Thank you very much for your suggestion, it has indeed pushed me further. I am using a stock GitLab Shared Runner.

With this the mysql client is found and successfully initialized, but when tests are run I get Error: ER_ACCESS_DENIED_ERROR: Access denied for user 'runner'@'' (using password: YES). I initially assumed that this runner will have a user with all privileges granted already. But that seems to not be the case. May I ask for a suggestion on the further steps I should take to overcome this? Thank you very much!

Hi @bmorkunas
you need to configure your mysql container using variables. Here is readme for mysql container on Docker Hub where you can find available variables.

Add variables keyword with variables to configure the mysql service. Example from official example.

  # Configure mysql environment variables (