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?

MySQLで開発環境のDBをバックアップ / リストアする

Posted at

mysqldump

システム関連のDBを除くすべてのDBをバックアップする

除外すべき一般的なシステムデータベース:
  - mysql - MySQLのユーザー・権限情報
  - information_schema - メタデータ(読み取り専用、ダンプ不可)
  - performance_schema - パフォーマンスデータ
  - sys - パフォーマンス監視用ビュー
.sql
# 除外したいデータベースのリスト
EXCLUDE_DBS="mysql|information_schema|performance_schema|sys"

# 対象データベースを取得してダンプ
DBS=$(mysql -umysql -proot -h 127.0.0.1 -N -e "SHOW DATABASES" | grep -Ev "^($EXCLUDE_DBS)$" | tr '\n' '
  ')

# dump
mysqldump -umysql -proot -h 127.0.0.1 --add-drop-database --databases $DBS > tmp/mysql-all-databases-dump-$(date "+%Y-%m-%d").sql

復元

.sql
mysql -umysql -proot -h 127.0.0.1 < tmp/mysql-all-databases-dump-2025-11-26.sql
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?