如果您使用的是innodb或具有完全事务性的另一个后端,则可以使用mysqldump --single-transaction ...
。我已经在相当大的数据库(〜100GB)上使用了它,并且效果很好。如果数据库负载沉重,则可能要花费数小时,但它确实可以工作而不会锁定表。复制通常更好,但有时您需要一个不错的可靠转储文件。请记住,您也可以转储mysql复制从站。
在mysqldump页面上(请注意有关将泄漏到事务中的操作的注意事项):
· --single-transaction
This option sends a START TRANSACTION SQL statement to the server
before dumping data. It is useful only with transactional tables
such as InnoDB, because then it dumps the consistent state of the
database at the time when BEGIN was issued without blocking any
applications.
When using this option, you should keep in mind that only InnoDB
tables are dumped in a consistent state. For example, any MyISAM or
MEMORY tables dumped while using this option may still change
state.
While a --single-transaction dump is in process, to ensure a valid
dump file (correct table contents and binary log coordinates), no
other connection should use the following statements: ALTER TABLE,
CREATE TABLE, DROP TABLE, RENAME TABLE, TRUNCATE TABLE. A
consistent read is not isolated from those statements, so use of
them on a table to be dumped can cause the SELECT that is performed
by mysqldump to retrieve the table contents to obtain incorrect
contents or fail.