我想将一个实时生产数据库复制到本地开发数据库中。是否有一种方法可以在不锁定生产数据库的情况下做到这一点?

我目前正在使用:

mysqldump -u root --password=xxx -h xxx my_db1 | mysql -u root --password=xxx -h localhost my_db1

但是它在运行时锁定了每个表。


当前回答

要转储大型表,您应该结合使用——single-transaction选项和——quick。

http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_single-transaction

其他回答

当使用MySQL工作台时,在数据导出中,单击高级选项并取消选中“锁定表”选项。

——lock-tables=false选项有效吗?

根据手册页,如果你正在转储InnoDB表,你可以使用——single-transaction选项:

--lock-tables, -l

Lock all tables before dumping them. The tables are locked with READ
LOCAL to allow concurrent inserts in the case of MyISAM tables. For
transactional tables such as InnoDB and BDB, --single-transaction is
a much better option, because it does not need to lock the tables at
all.

对于innodb DB:

mysqldump --single-transaction=TRUE -u username -p DB

由于https://dev.mysql.com/doc/refman/5.7/en/mysqldump.html#option_mysqldump_lock-tables:

有些选项,比如——opt(默认启用),会自动启用——lock-tables。如果您想覆盖这个选项,请在选项列表的末尾使用——skip-lock-tables。

要转储大型表,您应该结合使用——single-transaction选项和——quick。

http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html#option_mysqldump_single-transaction

——skip-add-locks帮了我大忙