我想将实时生产数据库复制到本地开发数据库中。有没有一种方法可以不锁定生产数据库?
我目前正在使用:
mysqldump -u root --password=xxx -h xxx my_db1 | mysql -u root --password=xxx -h localhost my_db1
但是它在运行时锁定每个表。
该--lock-tables=false选项有效吗?
--lock-tables=false
根据手册页,如果要转储InnoDB表,则可以使用以下--single- transaction选项:
--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