10
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CicleCiでCan't connect to local MySQL server through socket

Last updated at Posted at 2018-06-24

現象

CircleCiでdb:createを実行すると

Can't connect to local MySQL server through socket

というエラーになる。

原因

原因はdatabase.ymlでhostをlocalhostとしていること。

database.yml
default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password:
  host: localhost

対策

以下のように修正すると通るようになる。

database.yml
default: &default
  adapter: mysql2
  encoding: utf8
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  username: root
  password:
  host: <%= ENV['DB_HOST'] %> ←を修正

hostを環境変数を参照するように設定。

config.yml
version: 2
jobs:
  build:
    docker:
      - image: circleci/ruby:2.5.1-node-browsers
        environment:                 ←を追加
          DB_HOST: 127.0.0.1 ←を追加
      - image: circleci/mysql:5.7

CircleCiの設定ファイルにdatabase.ymlで修正した環境変数を追加する。

10
6
2

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
10
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?