Help us understand the problem. What is going on with this article?

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

More than 3 years have passed since last update.

基本

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
Why do not you register as a user and use Qiita more conveniently?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away