LoginSignup
190
203

More than 5 years have passed since last update.

MySQLでデータをエクスポートする

Posted at

基本

DBまるごとではなく、テーブルだけダンプしたい時

$ mysqldump -u user DB名 テーブル名A テーブル名B > dump.sql

上記の場合DROP TABLEやCREATE TABLEが同時に作成される。これらが必要ない時は「-t」オプション

$ mysqldump -u user -t DB名 テーブル名A テーブル名B > dump.sql

これでINSERT文だけとれる

テーブルの構成情報・スキーマのみ欲しい場合

$ mysqldump -u user --no-data DB名 > dump.sql

WHEREで指定したレコードのみダンプしたい

「--where(-w)」オプションを指定すると、whereが使える。指定テーブルだけではレコード数が多すぎて困るという場合や、予め必要なデータだけに絞ってダンプしたい場合に使う。かなり便利。

$ mysqldump -u user DB名 --where 'is_delete = 0' > dump.sql
190
203
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
190
203