运行MySQLDump而不锁定表

我想将一个实时生产数据库复制到我的本地开发数据库中。有没有办法在不锁定生产数据库的情况下执行此操作?


我目前正在使用:


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

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


芜湖不芜
浏览 3324回答 3
3回答

慕斯王

该--lock-tables=false选项是否有效?根据手册页,如果要转储InnoDB表,可以使用以下--single-transaction选项:--lock-tables, -lLock all tables before dumping them. The tables are locked with READLOCAL to allow concurrent inserts in the case of MyISAM tables. Fortransactional tables such as InnoDB and BDB, --single-transaction isa much better option, because it does not need to lock the tables atall.对于innodb DB:mysqldump --single-transaction=TRUE -u username -p DB

白板的微信

这已经太晚了,但对搜索主题的任何人都有好处。如果您不是innoDB,并且在转储时不担心锁定,只需使用以下选项:--lock-tables=false

Helenr

答案取决于您使用的存储引擎。理想的情况是你使用的是InnoDB。在这种情况下,您可以使用该--single-transaction标志,该标志将在转储开始时为您提供数据库的连贯快照。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

MySQL