EC2からRDSに接続しようとしたら「ERROR 2003 (HY000): Can’t connect to MySQL server」が出た
しばらく構築していないとさっぱり忘れてしまうのがAWSの設定
今回RDSを作成したので、EC2から接続しようとしたところ、、、
$ mysql -h mysql–instance1.123456789012.us-east-1.rds.amazonaws.com -P 3306 -u master_user -p Enter password: ERROR 2003 (HY000): Can't connect to MySQL server on 'kintaidb.cisfvswdjdlg.ap-northeast-1.rds.amazonaws.com' (110)
ん?接続できないとな!?
「ERROR 2003 (HY000): Can’t connect to MySQL server」
はじめはポート指定-P 3306
さえしていなかったので「はいはい」という感じだったのですが、
ポートを設定しても改善せず・・・
結論、セキュリティグループの設定不足
原因は非常に単純で、RDSさんが外からのアクセスを受け付けていませんでした。
なのでRDSに適用しているセキュリティグループの設定を変更します。
- 設定変更
DS作成時に特に設定していなければ「rds-launch-wizard-1 (sg-xxxxxxx)」みたいのが設定されているはずなので
以下のように変更
- 接続確認
$ mysql -h mysql–instance1.123456789012.us-east-1.rds.amazonaws.com -P 3306 -u master_user -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 332 Server version: 10.3.8-MariaDB-log Source distribution 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)]>
これで無事に繋がるようになりました。
(いつまでも覚えていられる頭がほしい。。)