LoginSignup
337
349

More than 5 years have passed since last update.

MySQLのデータインポート・エクスポート

Last updated at Posted at 2014-03-05

エクスポート

mysqldump -u[ユーザー名] -p[パスワード] -r [バックアップファイル名] --single-transaction [データベース名]

「sample」データベースを「sample.bakcup」としてバックアップしたい場合

mysqldump -usample_user -psample_password -r sample.bakcup --single-transaction sample

データベースの状態
データベース名:sample
ユーザー名:sample_user
パスワード:sample_password

オプションの解説

--single-transaction

ダンプ中にテーブルをREADロックしないように付与する。
(ただしテーブルのエンジンがMyISAMの場合はテーブルが変更されている場合があるので注意)

インポート

mysql -u[ユーザー名] -p[パスワード] [インポートするデータベース名] < [インポートするファイル名]


mysql -usample2_user -psample2_password sample2 < sample.bakcup

データベースの状態
データベース名:sample2
ユーザー名:sample2_user
パスワード:sample2_password
337
349
4

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
337
349