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.

mysqldumpの使い方

Posted at

DBのバックアップ

# DB内の全てのテーブルをバックアップ
$ mysqldump -u USER_NAME -p -h HOST_NAME DB_NAME > ファイル名.sql

# DB内の特定のテーブルをバックアップ
$ mysqldump -u USER_NAME -p -h HOST_NAME DB_NAME TABLE_NAME > ファイル名.sql

DBのリストア

# ダンプからDBを復元
$ mysql -u USER_NAME -p -h HOST_NAME DB_NAME < ファイル名.sql

mysqldumpの応用

例えばテストコード内でmysqldumpを取得したい場合など

test.php
$cmd = sprintf(
    "MYSQL_PWD=%s mysqldump -u %s -h %s %s > ファイル名.sql",
    config('database.connections.mysql.password'),
    config('database.connections.mysql.username'),
    config('database.connections.mysql.host'),
    config('database.connections.mysql.database'),
);
exec($cmd);
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?