LoginSignup
8
3

Amazon Linux 2023にsshログインしてMySQL Clientを入れてRDSインスタンスでSQLを実行する

Last updated at Posted at 2023-05-26

1. EC2インスタンスを作成

  • 秘密鍵を作成する
    • ~/.sshディレクトリに保存する
  • public subnetに作成する
  • public IPを割り当てる

2. sshログインする

.ssh/config
Host my-host
  User ec2-user
  HostName xx.xx.xx.xx
  IdentityFile ~/.ssh/xxx.pem

3. sshログイン

% chmod 700 .ssh
% chmod 600 .ssh/*
% ssh my-host
   ,     #_
   ~\_  ####_        Amazon Linux 2023
  ~~  \_#####\
  ~~     \###|
  ~~       \#/ ___   https://aws.amazon.com/linux/amazon-linux-2023
   ~~       V~' '->
    ~~~         /
      ~~._.   _/
         _/ _/
       _/m/'
Last login: Fri May 26 00:02:24 2023 from 114.150.224.148
[ec2-user@ip-xx-xx-xx-xx ~]$

4. EC2インスタンスにMySQL Clientをインストール

[ec2-user@ip-xx-xx-xx-xx ~]$ sudo su
[root@ip-xx-xx-xx-xx ec2-user]$ dnf -y localinstall https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm
[root@ip-xx-xx-xx-xx ec2-user]$ sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2023
[root@ip-xx-xx-xx-xx ec2-user]$ dnf -y install mysql mysql-community-client

5. MySQLに接続

[ec2-user@ip-xx-xx-xx-xx ~]$ mysql -h <host> -P <port> -u <user> <database> --password=<password>
...
mysql> SELECT 1;
+---+
| 1 |
+---+
| 1 |
+---+
1 row in set (0.00 sec)
8
3
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
8
3