MySQL Enterprise Backup:支持多种备份类型,包括全量备份、增量备份和差异备份。全量备份可以完整地备份数据库的所有数据文件;增量备份只备份自上次备份以来发生更改的数据部分,这对于频繁备份的场景非常有用,因为它可以减少备份所需的时间和存储空间;差异备份则备份自上一次全量备份以来所有更改的数据。MEB 提供了一些高级功能,如备份加密和压缩。加密功能可以保护备份数据的安全,防止数据泄露;压缩功能可以减少备份文件的大小,节省存储空间。此外,它还支持并行备份,可以利用多线程来提高备份性能。
CREATE USER 'mysqlbackup'@'localhost' IDENTIFIED BY 'password'; GRANT SELECT, BACKUP_ADMIN, RELOAD, PROCESS, SUPER, REPLICATION CLIENT ON *.* TO `mysqlbackup`@`localhost`; GRANT CREATE, INSERT, DROP, UPDATE ON mysql.backup_progress TO 'mysqlbackup'@'localhost'; GRANT CREATE, INSERT, DROP, UPDATE, SELECT, ALTER ON mysql.backup_history TO 'mysqlbackup'@'localhost';
mysqlbackup 客户端
MEB 使用 mysqlbackup 客户端进行备份和恢复数据。
查看 mysqlbackup 帮助信息。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
bash-5.1# mysqlbackup --help | head -n 20 MySQL Enterprise Backup Ver 8.4.4-commercial for Linux on x86_64 (MySQL Enterprise - Commercial) Copyright (c) 2003, 2025, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
MySQL Enterprise Backup Ver 8.4.4-commercial for Linux on x86_64 (MySQL Enterprise - Commercial) Copyright (c) 2003, 2025, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Starting with following command line ... mysqlbackup --user=mysqlbackup --password=xxxxxxxx --socket=/var/lib/mysql/mysql.sock --backup-image=my_full_bak.mbi --backup-dir=/tmp --show-progress --compress --with-timestamp backup-to-image
IMPORTANT: Please check that mysqlbackup run completes successfully. At the end of a successful 'backup-to-image' run mysqlbackup prints "mysqlbackup completed OK!".
250316 08:05:57 MAIN INFO: Establishing connection to server. 250316 08:05:57 MAIN INFO: No SSL options specified. 250316 08:05:57 MAIN INFO: MySQL server version is '8.4.4-commercial' 250316 08:05:57 MAIN INFO: MySQL server compile os version is 'Linux' 250316 08:05:57 MAIN INFO: Got some server configuration information from running server.
250316 08:05:57 MAIN INFO: Establishing connection to server for locking. 250316 08:05:57 MAIN INFO: No SSL options specified. 250316 08:05:57 MAIN INFO: Backup directory created: '/tmp/2025-03-16_08-05-57' 250316 08:05:57 MAIN INFO: MySQL server version_comment is 'MySQL Enterprise Server - Commercial' ... 250316 08:05:59 MAIN INFO: Compress Image Backup operation completed successfully. 250316 08:05:59 MAIN INFO: Image Path = /tmp/2025-03-16_08-05-57/my_full_bak.mbi 250316 08:05:59 MAIN INFO: MySQL binlog position: filename binlog.000003, position 1323.
------------------------------------------------------------- Parameters Summary ------------------------------------------------------------- Start LSN : 29611008 Last Checkpoint LSN : 29701923 End LSN : 29708609 -------------------------------------------------------------
mysqlbackup completed OK!
增量备份
MEB 支持基于从某个 LSN 开始备份,也可以基于上一个备份镜像做增量备份。
找到上次备份编号 END LSN 的方法:可以从备份日志中查询,或者在数据库里查看备份历史记录。
1 2 3 4 5 6 7
mysql> SELECT end_lsn FROM mysql.backup_history WHERE exit_state = 'SUCCESS'; +----------+ | end_lsn | +----------+ | 29708609 | +----------+ 1 row in set (0.00 sec)
MySQL Enterprise Backup Ver 8.4.4-commercial for Linux on x86_64 (MySQL Enterprise - Commercial) Copyright (c) 2003, 2025, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Starting with following command line ... mysqlbackup --user=mysqlbackup --password=xxxxxxxx --socket=/var/lib/mysql/mysql.sock --incremental --incremental-base=history:last_backup --backup-dir=/tmp/inc1 --backup-image=incremental_image1.bi backup-to-image
IMPORTANT: Please check that mysqlbackup run completes successfully. At the end of a successful 'backup-to-image' run mysqlbackup prints "mysqlbackup completed OK!".
250316 08:17:36 MAIN INFO: Establishing connection to server. 250316 08:17:36 MAIN INFO: No SSL options specified. 250316 08:17:36 MAIN INFO: MySQL server version is '8.4.4-commercial' 250316 08:17:36 MAIN INFO: MySQL server compile os version is 'Linux' 250316 08:17:36 MAIN INFO: Got some server configuration information from running server. ... 250316 08:17:36 RDR1 INFO: Writing server defaults files 'server-my.cnf' and 'server-all.cnf' for server '8.4.4-commercial' in '/tmp/inc1'. 250316 08:17:36 RDR1 INFO: Copying meta file /tmp/inc1/meta/backup_variables.txt. 250316 08:17:36 RDR1 INFO: Copying meta file /tmp/inc1/datadir/ibbackup_logfile. 250316 08:17:36 RDR1 INFO: Copying meta file /tmp/inc1/server-all.cnf. 250316 08:17:36 RDR1 INFO: Copying meta file /tmp/inc1/server-my.cnf. 250316 08:17:36 RDR1 INFO: Copying meta file /tmp/inc1/datadir/ibbackup_ibd_files. 250316 08:17:36 RDR1 INFO: Copying meta file /tmp/inc1/meta/backup_content.xml. 250316 08:17:36 RDR1 INFO: Copying meta file /tmp/inc1/meta/image_files.xml. 250316 08:17:36 MAIN INFO: Incremental Image Backup operation completed successfully. 250316 08:17:36 MAIN INFO: Backup image created successfully. 250316 08:17:36 MAIN INFO: Image Path = /tmp/inc1/incremental_image1.bi 250316 08:17:36 MAIN INFO: Backup contains changes from lsn 29708610 to lsn 29879497. 250316 08:17:36 MAIN INFO: MySQL binlog position: filename binlog.000003, position 1925.
------------------------------------------------------------- Parameters Summary ------------------------------------------------------------- Start LSN : 29708610 Last Checkpoint LSN : 29878489 End LSN : 29879497 -------------------------------------------------------------
mysqlbackup completed OK!
备份完成。
总结
本节内容介绍了什么是 MySQL Enterprise Backup,及其与 mysqldump 的对比。并演示如何使用 MEB,接下来,我们还可以借助操作系统的定时系统 crontab 定时对数据库进行备份。MEB 还有很多用法,我们后面继续介绍。