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
Hi Ravi!
Please note the caveats described in our service docs.
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
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.