概要
開発環境で 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'] %>
詳細
後日追加