Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

can't connect to mysql server - ruby container

francescob April 20, 2017

i'm trying to use the mysql service following instructions, but my rails tests fails because they can't connect:

 

#<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"=>"pipelines", "username"=>"test_user", "password"=>"test_user_password", "host"=>"localhost", "port"=>3306}, {:charset=>"utf8", :collation=>"utf8_unicode_ci"}

 

this is the relevant pipeline configuration:

 

services: 
         - mysql
definitions: 
  services: 
    mysql: 
      image: mysql
      environment: 
        MYSQL_DATABASE: pipelines
        MYSQL_ROOT_PASSWORD: my-secret-pw
        MYSQL_USER: test_user
        MYSQL_PASSWORD: test_user_password

and this is the database.yml:

test:
  adapter: mysql2
  database: pipelines
  username: test_user
  password: test_user_password
  host: localhost
  port: 3306

from the pipeline log the mysql instance seems to run OK, so i'm probably doing something wrong, any idea?

Thanks

Francesco

 

 

2 answers

5 votes
Matt Ryall
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 26, 2017
Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

This error message indicates that the Ruby MySQL client is trying to connect via a local, file-based "Unix socket", which won't work in Bitbucket Pipelines. The MySQL server is running in a separate container, so the client needs to use a TCP/IP connection for it to work.

I hit the same problem when using the command-line 'mysql' client in Pipelines, which connects via Unix sockets instead of via TCP if the hostname is 'localhost'. I'm guessing that the Ruby guys copied this logic into their client.

It should work if you change 'localhost' to '127.0.0.1' in your database.yml.

0 votes
caiquecssilva April 20, 2017

I'm having the same issue although I think you should use the name of the service 'mysql' as the host of the mysql database.

 

But i'd set the DB_HOST environment variable on the project's pipelines settings and it's not working and my project gets this value to set the host to connect to the database.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events