What's this?
RDSの任意のテーブルのダンプとる手法の備忘
注意
対象DBと対象テーブルは以下のように記載していますが、必要に応じて読み替えてください
対象DB:my_database
対象テーブル:my_table
やり方
1. RDSに接続ができる任意のサーバ(EC2など)に入る
2. RDSに接続できるか確認
[■■■@▼▼▼:/usr/bin][hh:mm:ss]$ sudo mysql -h 【RDSのエンドポイント】 -u 【mysqlユーザ名】 -p
RDSのエンドポイントはAWSマネジメントコンソールから確認可能
mysqlユーザ名は特に指定をしていないならadmin
[sudo] ■■■ のパスワード:【ユーザパスワード】
Enter password:【RDSのパスワード】
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is
Server version:
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]>
3. 対象のDBがあるか調べる
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| my_database |
| tmp |
+--------------------+
7 rows in set (0.01 sec) ※省略しています
4. 対象のテーブルがあるか調べる
MySQL [(none)]> use my_database;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
MySQL [my_database]> show tables;
+-----------------------+
| Tables_in_my_database |
+-----------------------+
| my_table |
+-----------------------+
2 rows in set (0.00 sec)
5. RDSとの接続を切る
MySQL [my_database]> exit
Bye
[■■■@▼▼▼:/usr/bin][hh:mm:ss]$
6. RDSの任意のテーブルのダンプを取得する
[■■■@▼▼▼:/usr/bin][hh:mm:ss]$ mysqldump -h 【RDSエンドポイント】 -u 【ユーザ名】 -t -p my_database my_table > my_table_yyyyMMdd.sql
- RDSのエンドポイントはAWSマネジメントコンソールから確認可能
- mysqlユーザ名は特に指定をしていないならadmin
- tオプションを付けることでcreate tableやdrop tableを省略した状態でのダンプが取得できます。復元に使用するときはtオプションを付けないようにしてください。
7. ダンプが取得されたことを確認する
任意の方法で実施してください。
私がやるとすると...
- llコマンドなどで、my_table_yyyyMMdd.sqlファイルが存在していること、更新日時があっていること、サイズが適当であることを調べる
- lessで開いて文字化けしていないことを調べる
とか?