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 3 years have passed since last update.

mysqlのdumpファイルから、特定のテーブルのdumpファイルを再構築する

Posted at

mysqlのテーブル指定をしていないdumpファイルから、指定したテーブルに該当するdumpだけを取り出す方法。

項目
データベースのdumpファイル all.dump
抽出したいテーブル HOGE
# "Table structure for table *****"の行で分割
$ csplit all.dump '/Table structure for table/' {*}

# 分割したファイルから、抽出したいテーブル名が含まれるファイル名の確認
$ grep -il 'HOGE' ./x*

# dumpファイルのヘッダを作成
$ head -16 > HOGE_tables.dump

# 結合
$ grep -il 'HOGE' ./x* | xargs -I {} cat {} >> HOGE_tables.dump


# dumpインポート
$ mysql --user=USER --password=PASSWORD DATABASE < HOGE_tables.dump

※ head -16 の行数は、mysqlのバージョンによるかもしれないので適宜調整する
※ HOGEがvalueとして含まれているファイルもマッチするので、その場合は適宜grepコマンドを調整する

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?