LoginSignup
0
0

More than 3 years have passed since last update.

EC2 デプロイ時にエラー

Posted at

エラー内容

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

あと一歩でデプロイ完了というところでこのようなエラーが出てしまいました...

原因

おそらくEC2上のMariaDBが起動していないことが原因でした。
以下の方法で私は起動ができましたが、起動するコマンドを直接うったわけではないので、もしかしたら特例かもしれません。

なので、起動コマンドをうってもうまくいかない人
などは試してみてください。

解決方法

とりあえずMySQLがインストールされていることを確認するために以下のコマンドで確認しましょう

mysql -v

インストールされていたら以下のコマンドをうって
私の場合はMariaDBの設定をしたので
その設定を行った時のパスワードをうって入って下さい。

mysql -u root -p

パスワードを入力するとこのようになったら成功です。

[root@ip-172-31-46-255 ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 5.5.64-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> 

次に以下のコマンドでテーブル一覧があるか確認してみてください。テーブルが現れたら正しくできているということになります。

MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| petter_production  |
+--------------------+
4 rows in set (0.00 sec)

テーブルが現れたら、次は、私の場合はpetter_production(自信のアプリにテーブル)に
テーブル一覧があるか確認します。

mysql -u root -D petter_production -p

MariaDB [petter_production]> show tables;
+-----------------------------+
| Tables_in_petter_production |
+-----------------------------+
| active_storage_attachments  |
| active_storage_blobs        |
| ar_internal_metadata        |
| comments                    |
| likes                       |
| pets                        |
| plans                       |
| relationships               |
| schema_migrations           |
| tweet_tag_relations         |
| tweet_tags                  |
| tweets                      |
| users                       |
+-----------------------------+
13 rows in set (0.00 sec)

ここまで確認したら、エラーが解決されました。
確認の一連でテーブル一覧が出てこなかったら設定がうまくいっていないので他のコマンドを探しみてください。

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