不锁定表格的情况下运行MySQLDump

6 浏览
0 Comments

不锁定表格的情况下运行MySQLDump

我想将现有的生产数据库复制到我的本地开发数据库中。有没有一种不锁定生产数据库的方法?

我目前正在使用:

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

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

admin 更改状态以发布 2023年5月22日
0
0 Comments

虽然有点晚了,但对于搜索此话题的人来说还是有益的。如果你不使用InnoDB,而且你不担心在导出数据时锁定,那么就使用该选项:

--lock-tables=false

0
0 Comments

--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数据库

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

0