LoginSignup
0
0

More than 1 year has passed since last update.

[お正月記事]ActiveRecord::ConnectionNotEstablished: Can't connect to local MySQL server through socket

Last updated at Posted at 2022-01-01

背景

docker-compose run backend rails db:migrate

をしようとしたところ
[+] Running 1/0
⠿ Container renote_mysql_1 Running 0.0s
rails aborted!
ActiveRecord::ConnectionNotEstablished: Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)
/app/bin/rails:10:in <top (required)>'
/app/bin/spring:15:in
'
/app/bin/rails:3:in load'
/app/bin/rails:3:in
'

Caused by:
Mysql2::Error::ConnectionError: Can't connect to local MySQL server through socket '/run/mysqld/mysqld.sock' (2)
/app/bin/rails:10:in <top (required)>'
/app/bin/spring:15:in
'
/app/bin/rails:3:in load'
/app/bin/rails:3:in
'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
のエラーが出て入力できず。

解決

mysql -u root -p

とかしてmysqlに入れるか、mysqlのstatusはrunningになっているか等の確認をしていたのですが、結論としては.envファイルがありませんでした。

git  clone

すると最初は.envファイルはなくなり自分で作らないといけないそうです。
.envファイルを作るアプリケーションディレクトリに作り、元の.envファイルの中身をコピペすると解決しました。

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