LoginSignup
18
22

More than 5 years have passed since last update.

mysqlのmysqldumpからテーブル指定で復元

Last updated at Posted at 2015-12-01

概要

mysqldump取った!リリースした!バグってた!復元だ!復元は1テーブルだけでいい。他のテーブルは復元したくない!
って時のためのテーブル単位復元方法。

mysqldumpの取得

mysqldump -u user_name -t schema_name > 20151201.sqldump

sqldumpファイルをテーブル名ごとに別ファイルに出力

csplit backup_20151201.sql '/DROP TABLE IF EXISTS/' {*}

これで、DROP TABLE IF EXISTが最初の行のファイルが実行ディレクトリに分割されて出来上がる。
ファイル名は「xx01」のような形の連番。

復元したいテーブルのファイルを探す。

grep -il 'create table `TARGET_TABLE_NAME`' ./xx*

復元

mysql -u user_name -t schema_name < xx0N

でOK。

18
22
3

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
18
22