不锁定表格的情况下运行MySQLDump
不锁定表格的情况下运行MySQLDump
我想将现有的生产数据库复制到我的本地开发数据库中。有没有一种不锁定生产数据库的方法?
我目前正在使用:
mysqldump -u root --password=xxx -h xxx my_db1 | mysql -u root --password=xxx -h localhost my_db1
但它在运行时会锁定每个表。
admin 更改状态以发布 2023年5月22日
--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