我想将一个实时生产数据库复制到本地开发数据库中。是否有一种方法可以在不锁定生产数据库的情况下做到这一点?
我目前正在使用:
mysqldump -u root --password=xxx -h xxx my_db1 | mysql -u root --password=xxx -h localhost my_db1
但是它在运行时锁定了每个表。
我想将一个实时生产数据库复制到本地开发数据库中。是否有一种方法可以在不锁定生产数据库的情况下做到这一点?
我目前正在使用:
mysqldump -u root --password=xxx -h xxx my_db1 | mysql -u root --password=xxx -h localhost my_db1
但是它在运行时锁定了每个表。
当前回答
——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
其他回答
这已经太迟了,但对任何正在搜索这个话题的人来说都是好事。如果你不是innoDB,并且你不担心转储时锁定,那么就使用这个选项:
--lock-tables=false
另一个迟来的回答是:
如果您正在尝试对服务器数据库进行热复制(在linux环境中),并且所有表的数据库引擎都是MyISAM,您应该使用mysqlhotcopy。
相应的文件:
它使用FLUSH TABLES、LOCK TABLES和cp或scp来创建数据库 备份。这是一种快速备份数据库或单个数据库的方法 表,但是它只能在数据库所在的同一台机器上运行 目录被定位。Mysqlhotcopy只适用于备份 MyISAM和ARCHIVE表。
LOCK TABLES时间取决于服务器复制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
答案取决于您使用的存储引擎。最理想的情况是使用InnoDB。在这种情况下,您可以使用——single-transaction标志,它将在转储开始时为您提供数据库的一致快照。
——skip-add-locks帮了我大忙