Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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
Community showcase
Published in Bitbucket

📣 Calling Bitbucket Data Center customers to participate in research

Hi everyone, Are you Bitbucket DC customer? If so, we'd love to talk to you! Our team wants to dive deep to understand your long-term plans regarding Bitbucket DC and Atlassian Cloud. Do you plan...

111 views 2 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you