LoginSignup
9
4

More than 3 years have passed since last update.

ERROR 2003 (HY000): Can't connect to MySQL server on

Posted at

事象 : RDSのMySQLに接続しようとしたらできなかった

  • 環境
    • Windows10 Pro バージョン1909
    • GitBash ※. GitBashを使用しているのでmysqlコマンドの前にwinptyをつけている
$ winpty mysql -h db-shikibetushi.abcdefg.region.rds.amazonaws.com -P 3306 -u username -p
Enter password: ************
ERROR 2003 (HY000): Can't connect to MySQL server on 'db-shikibetushi.abcdefg.region.rds.amazonaws.com' (10060)

原因 : セキュリティグループのインバウンドルールにIPアドレスがないから

うまく接続できない場合は、RDSの[パブリックアクセシビリティ]またはセキュリティグループの設定が誤っています。
RDSでMySQLを作ってみる - ponsuke_tarou’s blog

同じことに何度も引っかかる自分が憎い・・・

  1. AWSコンソール > [RDS] > [データベース] > 対象のDB識別子リンクで詳細画面表示
  2. [接続とセキュリティ]タブ > [VPC セキュリティグループ]のリンクで[セキュリティグループ]画面表示 image.png
  3. 対象のセキュリティグループリンクで詳細画面表示 [インバウンドルール]タブimage.png
  4. ここに自分が使っているパブリックIPアドレスがないと接続できない

対応 : インバウンドルールにIPアドレスを設定する

  1. [インバウンドルール編集]ボタンでダイアログを表示
  2. [ルールの追加]ボタンで行を追加して以下を設定
    • タイプ : MySQL/Aurora
    • プロトコル : TCP
    • ポート範囲 : 3306(MySQLのポート)
    • ソース : カスタム / 「{自分のパブリックIPアドレス}/32」
    • 説明 : 後でなんのIPアドレスかわかるような説明
  3. [ルールを保存]ボタンで保存する image.png
再び接続してみるとつながった
$ winpty mysql -h db-shikibetushi.abcdefg.region.rds.amazonaws.com -P 3306 -u username -p
Enter password: ************
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 458689
Server version: 5.6.40-log Source distribution

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>
9
4
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
9
4