简体   繁体   English

MySQL InnoDB 表在导出时锁定

[英]MySQL InnoDB table locking on export

I have an InnoDB MySQL database.我有一个InnoDB MySQL 数据库。 When I export a SQL dump, how does the locking occur?当我导出SQL转储时,锁定是如何发生的? Does the entire database lock during the export?导出期间整个数据库是否锁定? Or just the table?还是只是桌子? Or just the individual rows?或者只是单独的行? How exactly does the export work with InnoDB ? InnoDB的导出究竟是如何工作的?

You can control what is locked.您可以控制锁定的内容。

To be safest, you can lock all tables like this:为了最安全,您可以像这样锁定所有表:

mysqldump --lock-all-tables

Docs: Lock all tables across all databases. Docs:锁定所有数据库中的所有表。 This is achieved by acquiring a global read lock for the duration of the whole dump.这是通过在整个转储期间获取全局读锁来实现的。 This option automatically turns off --single-transaction and --lock-tables.此选项会自动关闭 --single-transaction 和 --lock-tables。

Or if you're sure you're not going to alter tables:或者,如果您确定不打算更改表:

mysqldump --single-transaction

Docs: 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.文档:在处理 --single-transaction 转储时,为确保转储文件有效(正确的表内容和二进制日志坐标),其他连接不应使用以下语句:ALTER TABLE、CREATE TABLE、DROP TABLE、RENAME 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.一致性读取与这些语句不隔离,因此在要转储的表上使用它们可能会导致 SELECT 执行的 mysqldump 检索表内容以获取不正确的内容或失败。

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

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