title: Unable to connect to MySql using gitlab-ci.yml
body: <p>I'm trying to create gitlab-ci file for my Rails project.  A part of my .gitlab-ci.yml:</p>
  
  <pre><code>image: ruby:2.3.4
  
  variables:
    RAILS_ENV: test
  
  services:
    - mysql:5.7
  
  
  before_script:
    - apt-get update -qq &amp;&amp; apt-get install -yqq nodejs libmysqlclient-dev
    - ruby -v
    - which ruby
    - gem install bundler --no-ri --no-rdoc
    - bundle install --jobs $(nproc) "${FLAGS[@]}"
    - cp config/database.gitlab_ci.yml config/database.yml
    - bundle exec rake db:create db:schema:load
    - bundle exec rake db:migrate --quiet
  </code></pre>
  
  <p>I haven't been able to get it to connect to my MySql db. No matter what I tried. </p>
  
  <p>Here's a part of my database.gitlab_ci.ym:</p>
  
  <pre><code>test: &amp;test
      adapter: mysql2
      database: my_db
      encoding: utf8
      username: my_user
      password: 1234
      host: localhost
  </code></pre>
  
  <p>I've always gotten this error:</p>
  
  <pre><code>  #&lt;Mysql2::Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)&gt;
    Couldn't create database for {"adapter"=&gt;"mysql2", "database"=&gt;"my_db", "encoding"=&gt;"utf8", "username"=&gt;"my_db", "password"=&gt;1234, "host"=&gt;"localhost"}, {:charset=&gt;"utf8"}
    (If you set the charset manually, make sure you have a matching collation)
    rake aborted!
    Mysql2::Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
  </code></pre>
  
  <p>How to fix it?</p>