LoginSignup
0
0

More than 1 year has passed since last update.

EC2データベースマイグレーションできない

Posted at

やろうとしたこと

ec2上でphp artisan migrateを実行してデータベースマイグレーションしようとを思ったらハマってしまったのでメモしておきます。

エラー内容

$ php artisan migrate

**************************************
*     Application In Production!     *
**************************************

 Do you really wish to run this command? (yes/no) [no]:
 > yes


In Connection.php line 669:

  SQLSTATE[HY000] [2002] Connection timed out (SQL: select * from information_schema.tables where table_sc  
  hema = larans and table_name = migrations and table_type = 'BASE TABLE')                                  


In Connector.php line 70:

  SQLSTATE[HY000] [2002] Connection timed out

データベースに接続できなくてタイムアウトしてしまいました。

原因

インバウンドルールでEC2インスタンスで使用しているセキュリティグループではなかったためでした。

対策

  1. RDSのセキュリティからVPCセキュリティグループを選択。
  2. 次にインバウンドルールからインバウンドのルールを編集を選択。
  3. ソースにEC2インスタンスで使用しているセキュリティグループを設定

スクリーンショット 2021-11-06 19.54.30.png

<考察> なぜインバウンドルールをセキュリティグループにするのか

ec2からrdsに接続するためec2のセキュリティグループをインバウンドルールで許可し、ec2からの接続を可能にするためだと思います。

参考

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