简体   繁体   English

所有InnoDB表环境上的Mysql备份

[英]Mysql Backup on all InnoDB tables environment

At the moment I am doing the backup with mysqlbackup. 目前,我正在使用mysqlbackup进行备份。 This will call "FLUSH TABLES WITH READ LOCK" and rise the possibility of locking my tables until the flush is done and the global lock released. 这将称为“带读取锁定的表刷新”,并增加了锁定我的表的可能性,直到完成刷新并释放全局锁定为止。

So, is there anyway to backup my database, which is really big, there are tables with more than 100 GB, without this global lock ? 因此,是否有任何备份我的数据库的方法,这确实很大,没有超过100 GB的表却没有此全局锁定?

Something like mysqldump --single-transaction , which I read is useful on small DBs, which is not the case. 我读过的mysqldump --single-transaction之类的东西在小型数据库上很有用,事实并非如此。 Is there sometinh similar appliable to my case ? 有没有类似的适用于我的情况?

Hope so ! 希望如此 !

Percona Xtrabackup is an excellent option when you have tables that large. 当表很大时,Percona Xtrabackup是一个很好的选择。 This is mainly due to the following two points: 这主要是由于以下两点:

a) Time taken to restore a 100GB table from a logical backup (ie: created by mysqldump) would be excessive, since mysql has to rebuild indexes and do a lot of I/O processing as the sql is replayed in. a)从逻辑备份(即:由mysqldump创建)恢复100GB表所花费的时间会过多,因为在重播sql时mysql必须重建索引并进行大量I / O处理。

b) xtrabackup can take incremental backups after you have made your first full backup, making routine nightlies or hourlies much quicker and smaller in terms of disk space. b)在您进行第一次完全备份后,xtrabackup可以进行增量备份,从而使例行的夜间或小时备份变得更快,更小。

That said, be aware that because xtrabackup copies all relevant files in the /lib/mysql directory, the diskspace requirements are significant. 就是说,请注意,因为xtrabackup复制/ lib / mysql目录中的所有相关文件,所以磁盘空间要求非常重要。 If you have a database which has 200GB allocated on disk (even if there is some empty allocated space on some tables), your backup will be 200GB in size. 如果您的数据库在磁盘上分配了200GB(即使某些表上有一些空的分配空间),则备份大小将为200GB。

This is compared to mysqldump's logical backup (sql statements which can recreate the data, table structures, indexes etc), which will take up a tiny fraction of the space. 相比之下,这与mysqldump的逻辑备份(可以重新创建数据,表结构,索引等的sql语句)占用的空间很小。

Read more about how Percona xtrabackup works here: https://www.percona.com/doc/percona-xtrabackup/LATEST/how_xtrabackup_works.html 在此处阅读有关Percona xtrabackup工作原理的更多信息: https ://www.percona.com/doc/percona-xtrabackup/LATEST/how_xtrabackup_works.html

mysqldump used with innodb tables and a combination of --master-data and --single-transaction option is a good option to consider. 与innodb表一起使用的mysqldump以及--master-data和--single-transaction选项的组合是一个不错的选择。 It acquires a global read lock on all tables, but only for long enough to read the binary log coordinates. 它在所有表上都获得了全局读锁定,但是时间足够长,无法读取二进制日志坐标。 Typically this will be very quick, unless there are very significant updates in progress, in which case it could stall until the updates complete. 通常,这将非常快,除非正在进行非常重要的更新,在这种情况下,它可能会暂停直到更新完成。

This gives you a consistent point-in-time backup, and there is no locking beyond the initial read lock. 这样可以为您提供一致的时间点备份,并且没有超出初始读取锁定的锁定。

Here is the syntax: 语法如下:

  mysqldump --all-databases --master-data --single-transaction > all_databases.sql

or 要么

  mysqldump --master-data --single-transaction my-database > my-database.sql

to back up a single database. 备份单个数据库。

More information about this can be read on the dev.mysql.com site here: https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_single-transaction 可以在dev.mysql.com网站上阅读有关此内容的更多信息: https : //dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_single-transaction

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM