0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

dumpファイルの取得

Posted at

背景

  • RDSバージョンアップで慎重に行う必要のある作業が発生し、バックアップも慎重に行う必要があるとのことでdumpファイルの取得が必要になった。
  • sqlをインストール済みの仮想環境にてdumpファイルの取得を行い、復元を試みる

DBの現状

  • テスト環境ということで適当にデータを入れたDBを作成した
    mysql> show tables;
    +----------------+
    | Tables_in_test |
    +----------------+
    | KingList |
    | NameList |
    +----------------+
    mysql> SELECT * from NameList;
    +------+------+
    | ID | Name |
    +------+------+
    | 1 | 2 |
    | 1 | 123 |
    | 1 | 555 |
    | 8 | 550 |
    +------+------+
    mysql> SELECT * from KingList;
    +------+------+
    | ID | Name |
    +------+------+
    | 100 | 5212 |
    +------+------+

dumpの取得

$ mysqldump -h localhost.localdomain -u root -t -p test > dump.sql
※testはDB名、localhost.localdomainはRDSのホスト名、ルートはユーザー名

  • 取得できたか確認
    $ ll
  • 中身に文字化けがないか確認
    $ less dump.sql

dumpを試す

  • まず、テーブルの削除を行う
    テーブル「NameList」「KingList」を削除し、同名で作りなおし中身を空にする
  • 空のテーブルが用意されている確認
    mysql> SELECT * from NameList;
    Empty set (0.01 sec)

mysql> SELECT * from KingList;
Empty set (0.01 sec)

  • ダンプファイルを実行する
    $ mysql -u root -p test < dump.sql

  • 復元できたか確認する
    mysql> SELECT * from NameList;
    +------+------+
    | ID | Name |
    +------+------+
    | 1 | 2 |
    | 1 | 123 |
    | 1 | 555 |
    | 8 | 550 |
    +------+------+
    4 rows in set (0.00 sec)

mysql> SELECT * from KingList;
+------+------+
| ID | Name |
+------+------+
| 100 | 5212 |
+------+------+
1 row in set (0.01 sec)

  • テーブルのデータが復元できたことが確認できた
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?