I'm trying to create gitlab-ci file for my Rails project. A part of my .gitlab-ci.yml:
image: ruby:2.3.4
variables:
RAILS_ENV: test
services:
- mysql:5.7
before_script:
- apt-get update -qq && 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
I haven't been able to get it to connect to my MySql db. No matter what I tried.
Here's a part of my database.gitlab_ci.ym:
test: &test
adapter: mysql2
database: my_db
encoding: utf8
username: my_user
password: 1234
host: localhost
I've always gotten this error:
#<Mysql2::Error: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)>
Couldn't create database for {"adapter"=>"mysql2", "database"=>"my_db", "encoding"=>"utf8", "username"=>"my_db", "password"=>1234, "host"=>"localhost"}, {:charset=>"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)
How to fix it?
Your mysql service won't be available at localhost
.
You have to use the service name mysql
as hostname.
See Documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With