0
1

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.

現場でよく使うmysqldumpコマンド

Posted at

業務でmysqldumpコマンドを使用する時、あれ?こうしたい時ってどういうコマンドだっけなって毎回なるので、備忘録として残しておきます。
主にテーブル単位でデータをdmpする場合を想定しています。

dmpコマンド

MySQLからデータをdmpするコマンドになります。

テーブル定義とデータのdmp

mysqldump -u [user_name] -p -h [host_name] [db_name] [table_name] > output.dmp

テーブル定義のみdmp

mysqldump -u [user_name] -p -h [host_name] [db_name] [table_name] -d -n > output.dmp

テーブルデータのみdmp

mysqldump -u [user_name] -p -h [host_name] [db_name] [table_name] -t > output.dmp

WHERE句を使用したdmp

mysqldump -u [user_name] -p -h [host_name] --where "id >= 100" [db_name] [table_name] > output.dmp

複数テーブルのdmp

mysqldump -u [user_name] -p -h [host_name] [db_name] [table_name1] [table_name2] [table_name3] > output.dmp

リストアコマンド

dmpファイルからMySQLにデータをリストアするコマンドになります。

mysql -u [user_name] -p [db_name] < output.dmp

現場からは以上です。

0
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?