Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

This article is a Private article. Only a writer and users who know the URL can access it.
Please change open range to public in publish setting if you want to share this article with other users.

More than 3 years have passed since last update.

MySQLのデータベースのバックアップとリストア

Last updated at Posted at 2019-09-30

基本

↓がされている前提。

create database hoge;

初回のみ(バックアップ用のデータベース生成)

mysqladmin create hoge_bk

常時(ダンプ生成とダンプをバックアップ用のデータベースへ流す)

mysqldump hoge > dump.sql && mysql hoge_bk < dump.sql

hoge_bkからのリストア(バックアップ用のデータベースから、select insert)

insert into hoge.table_name1 (select * from hoge_bk.table_name1);

※もしくはレコードだけダンプして、それをバックアップ用に入れる

Create Databaseから取得する

mysqldump -h host_name -u user -p --skip-lock-tables -A > dump.sql

補足

  • LOCK TABLESが云々の場合、オプションに↓をつける
    --skip-lock-tables

  • -A はすべてのスキーマを取得するオプション

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?