Skip to content
> giho's blog
Go back

~/posts/mysql-backup-recovery

MySQL 백업 복구 정리

· 4 min read
-- contents

시작하며

MySQL(MariaDB)에서 많이 쓰이는 backup 도구는 mysqldump와 xtrabackup(mariabackup)이 있다. 간단한 사용 방식들을 정리해 본다.

mysqldump

MySQL을 논리적으로 백업하는 도구이다. 사용법이 간단해서 작은 규모의 디비를 백업&복구할 때 사용하고 있다.

mysqldump --all-databases > dump.sql 명령어로 간단하게 백업을,

mysql < dump.sql 명령어로 복구를 할 수 있다.

실제로는 여러 옵션을 넣어서 사용하고 있다.

mysqldump --routines --events --single-transaction --max_allowed_packet=512M --master-data=2 --all-databases > /DATA/backup/dump_$DAY.sql

xtrabackup(mariabackup)

xtrabackup —user=id—password=pw—backup —no_lock —target-dir=./

mysql shell

스터디에서 mysql shell로 백업&복구하는 방법에 대해서 얘기가 나왔다. 기존에 위에 두 가지 방법으로만 백업을 수행했는데 mysql shell이 속도가 더 빠르다는 얘기를 듣고 직접 테스트한 결과를 적어본다.

설치

wget https://dev.mysql.com/get/Downloads/MySQL-Shell/mysql-shell-8.0.32-linux-glibc2.12-x86-64bit.tar.gz

접속

./mysqlsh --uri={id}@127.0.0.1:{port} --password={pw}
or
./mysqlsh -uri {id}@127.0.0.1:{port} -p{pw}

명령어

\sql, \py 등의 명령어로 입력 모드를 변경할 수 있다

util.dumpInstance("/root/mysqlsh_test/",
 {threads: 8,
 showProgress: true,
 users: false})

20c 128g 백업 376G 스레드10 : 6분 58초, 원격지 15분 스레드20 : 5분 16초

복구

util.loadDump("/root/mysqlsh_test/",
 {threads: 8,
 ignoreExistingObjects:true,
 resetProgress:true})

Util.loadDump: Unknown system variable 'server_uuid' (MYSQLSH 1193)

복구할 때 오류가 발생한다.

show variables like ‘server_uuid’;

Empty set (0.0017 sec)

없네…. 마리아에서는 안 되겠다…

나중에 mysql에서 다시 해보자..



-- related


Previous Post
selenium 크롤링 팁 몇 가지
Next Post
MySQL 시스템 변수 정리 — 연결·버퍼·InnoDB 핵심
giho=#searchesc