0
0

More than 3 years have passed since last update.

[Rails] MySQL(clearDB) で Heroku にデプロイ時、Mysql2::Error::ConnectionError の解決策

Last updated at Posted at 2021-05-14

概要

開発環境で MySQL ( gem 'mysql2' ) を利用してDBにオブジェクトの新規作成・保存できていたのに、本番環境のDBが作成できない時の解決策をまとめる。

発生時に実行され、表示されたエラー

Terminal
$ heroku run rails:db migrate

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

結論

  • clearDB の設定項目で入力漏れがあった
$ heroku config

#=> CLEARDB_DATABASE_URL: <作成した clearDB のURL>

$ heroku config:add DATABASE_URL='上記のURL'

事前設定

config/database.yml(変更前)
production:
  <<: *default
  database: test_app_production
  password: <%= ENV['TEST_APP_DATABASE_PASSWORD'] %>
config/database.yml(変更後)
production:
  <<: *default
  url: <%= ENV['DATABASE_URL'] %>
  database: test_app_production
  password: <%= ENV['TEST_APP_DATABASE_PASSWORD'] %>

詳細

後日追加

参考URL

0
0
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
0
0