[英]Unable to connect to MySql using gitlab-ci.yml
I'm trying to create gitlab-ci file for my Rails project. 我正在尝试为我的Rails项目创建gitlab-ci文件。 A part of my .gitlab-ci.yml:
我的.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. 我无法连接到我的MySql数据库。 No matter what I tried.
无论我怎么做。
Here's a part of my database.gitlab_ci.ym: 这是我的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 issue seems similiar to this . 您的问题似乎与此类似。 The workaround mentioned there is that you need to connect via TCP, not socket.
提到的解决方法是你需要通过TCP连接,而不是socket。
Also I'd suggest you that you check gitlab's documentation related to MySQL service. 另外我建议你检查gitlab与MySQL服务相关的文档 。
Your mysql service won't be available at localhost
. 您的mysql服务将无法在
localhost
。
You have to use the service name mysql
as hostname. 您必须使用服务名称
mysql
作为主机名。
See Documentation . 见文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.