LoginSignup
8
5

More than 3 years have passed since last update.

【Github Actions】Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Posted at

事象

Github Actionsで突然Mysqlに接続できなくなった

Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

原因

2020/3/12から、Github ActionsのUbuntuで
Mysqlが自動起動しなくなったため

解決策

workflowにMysqlを起動させるコマンドを追加

- run: |
    sudo /etc/init.d/mysql start

修正後ソース

name: Ruby

on:
  push:
  pull_request:
    branches: [ master ]

jobs:
  build:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Set up Ruby 2.5
      uses: actions/setup-ruby@v1
      with:
        ruby-version: 2.5.x
    - name: Budle install
      run: |
        gem install bundler
        bundle install --jobs 4 --retry 3
    - name: Setup Database
      run: |
        cp config/database.yml.ci config/database.yml
        sudo /etc/init.d/mysql start # ここを追加
        bundle exec rake db:create
        bundle exec rake db:schema:load
      env:
        RAILS_ENV: test
    - name: test with Rake
      run: |
        bundle exec rake
      env:
        RAILS_ENV: test

最後に

公式ドキュメントちゃんと読みましょうという話

8
5
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
5