Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/var/run/mysqld/

ravi February 22, 2021

Hi All, 

I am trying to build a pipeline configuration.  But facing issues related to mysql connectivity. 

I get the following error: 

Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/var/run/mysqld/

 

Below is my bitbucket-pipelines.yml

image: ruby:2.5

pipelines:
default:
- step:
caches:
- bundler
- yarn
services:
- mysql
script:
- curl -sL https://deb.nodesource.com/setup_8.x | bash -
- apt-get update && apt-get install -y nodejs apt-transport-https
- curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
- echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
- apt-get update
- apt-get install -y xvfb yarn qt5-default libqt5webkit5-dev gstreamer1.0-plugins-base gstreamer1.0-tools gstreamer1.0-x
- yarn install
- export DATABASE_URL=mysql2://root:mysql@localhost/rspec_db
- cp config/database.ci.yml config/database.yml
- bundle install --path vendor
- RAILS_ENV=test bundle exec rake db:test:prepare
- xvfb-run -a bundle exec rspec

definitions:
caches:
bundler: ./vendor
yarn: ./node_modules
services:
mysql:
image: mysql:5.7
environment:
MYSQL_DATABASE: 'rspec_db'
MYSQL_ROOT_PASSWORD: 'mysql'

 

Please find database.yml for  reference

default: &default
adapter: mysql2
encoding: utf8mb4
username: root
password: mysql
port: 3306
host: 127.0.0.1

development:
<<: *default
database: rspec_db

test:
<<: *default
database: rspec_db

 

1 answer

0 votes
Eddie Webbinaro
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
February 24, 2021

Hi Ravi!

Please note the caveats described in our service docs.

https://support.atlassian.com/bitbucket-cloud/docs/databases-and-service-containers/#MySQL-%E2%80%93-test-user

 Host name: 127.0.0.1 (avoid using localhost, as some clients will attempt to connect via a local "Unix socket", which will not work in Pipelines)


It looks like your default DB in database.yml s trying to use 127.0.0.1 correctly, BUT you are explicitly overriding that in pipeline config line:

- export DATABASE_URL=mysql2://root:mysql@localhost/rspec_db

Instead, either remove that and just use database.yml, or change to 127...

- export DATABASE_URL=mysql2://root:mysql@127.0.0.1/rspec_db 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events