3
2

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 3 years have passed since last update.

heroku run rails db:migrateでのMysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)エラー

Posted at

#herokuでmysqlを使った時のデプロイエラー

##エラー内容

terminal
$ heroku run rails db:migrate
Running rails db:migrate on  ~~~... up, run.9919 (Free)
rails aborted!
Mysql2::Error: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

##解決法

$ heroku config

=== app名 Config Vars
LANG:                     en_US.UTF-8
RACK_ENV:                 production
RAILS_ENV:                production
RAILS_LOG_TO_STDOUT:      enabled
RAILS_SERVE_STATIC_FILES: enabled
SECRET_KEY_BASE: ~~~~~~~

どうやら、DBをmysqlに設定しないといけないらしい。

$ heroku addons:add cleardb
Creating cleardb on ⬢ app... free
Created cleardb-shaped-01808 as CLEARDB_DATABASE_URL
Use heroku addons:docs cleardb to view documentation
$ heroku config | grep CLEARDB_DATABASE_URL #~~~~~のところに、あなたのURLが出てくる。
CLEARDB_DATABASE_URL:     mysql://~~~~~~~~
$ heroku config:set DATABASE_URL=mysql2://~~~~~~~ #さっきのURL
Setting DATABASE_URL and restarting ⬢ app... done, v16
DATABASE_URL: mysql2://~~~~~~~ #設定できた
$ heroku run rails db:migrate
Running rails db:migrate on ⬢ app... up, run.5102 (Free)

これで、できた!

あとは、$ heroku open で確認すると🙆‍♂️

以上!

3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?