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 1 year has passed since last update.

【MySQL】dumpファイルを使用したリストア方法

Posted at

各自の開発環境のデータベースの状態を合わせるときなど、dumpファイルを入手してリストアする必要があります。

※ここではデータベースの中身を合わせたい環境からdumpファイルを入手したところから解説します。

dumpファイルを保存

入手したdumpファイル(sample.dump)を各自の環境に保存します。
(仮想環境の場合はファイル転送ツールなどを使用して保存)

今回はCentOS7の仮想環境で以下の階層にdumpディレクトリを作成して、ここにdumpファイルを保存します。

/var/lib/mysql/dump/sample.dump

リストア先のデータベースの準備

もしデータベースを未作成の場合、あらかじめDBを作成しておく必要があります。
mysqlにログイン状態で以下のコマンドを実行

CREATE DATABASE データベース名;

dumpファイルのある階層へ移動してリストアを実行

dumpファイルを保存した階層へ移動します。

cd /var/lib/mysql/dump

移動した先で以下のコマンドを実行します。※mysqlに未ログイン状態で実行

mysql -u ユーザー名 -p データベース名 < sample.dump

※データ量によっては結構時間がかかるので注意。

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?