[MySQL]DBのdumpとrestore

LINEで送る
Pocket

  • dump(メンテナンスしない場合)
$ mysqldump -v --single-transaction --skip-lock-tables -h hoge -u root -p -P xxxxx DB-name| gzip > ~/backup/$(date "+%Y%m%d")/bk.$(date "+%Y%m%d").gz
  • dump(メンテする場合)
mysqldump -v --extended-insert --quick --quote-names --single-transaction --set-gtid-purged=OFF -h hoge -u hoge -p hoge-db | gzip > ./$(date "+%Y%m%d").sql.gz
  • restore
zcat $(date "+%Y%m%d").gz | mysql -u hoge -h xxxxxxx -p db_name

  • mysql8 dump
mysqldump -v --skip-column-statistics --skip-lock-tables --single-transaction -h hoge -u hoge -p db -P 1234 --set-gtid-purged=OFF > hoge.sql
  • mysql dump db名も一緒にする場合
mysqldump -v --single-transaction --skip-lock-tables -h "${HOST}" -u "${USER}" -p"${PWD}" hoge1 | sed 's/'hoge1'/'hoge2'/g' | gzip > ~/backup/bk_$(date "+%Y%m%d").gz

  • シンプル dump 
$ mysqldump -v --skip-lock-tables -h hoge -u root -p hoge | gzip > bk.$(date "+%Y%m%d").gz
  • シンプルrestore
$ zcat bk.20200907.gz | mysql -u root -h xxxxxxxxxxxxx -p hoge

$ mysql -u username -h hoge -p -D DBname < dumpfilename.sql

 

Was this helpful?

0 / 0

コメントを残す 0

Your email address will not be published. Required fields are marked *