You don't necessarily have to take mysqld offline or change the port. You can use FLUSH TABLES WITH READ LOCK to ensure no writes happen while you're noting the binlog position and creating the dump.
Restoring a dump usually takes a long time, probably a lot longer than it took to create the dump. If your master is recording a very high rate of new changes, then yes, it may take a while for the replica to catch up once you finish the restore on the replica and start replication.
An alternative you can use, if shutting down mysqld is acceptable, is to copy the physical data directory from master to replica, instead of doing the dump and restore. So initializing the replica can be very quick, basically just as long as it takes to run rsync to copy the files from one server to the other.
note: You must shut down mysqld on master and replica as you do this, otherwise you have a risk that some of the data is buffered and won't be included in the file copy. Remember to check file ownership and permissions on the replica before starting mysqld on the replica.
You should read these sections from the manual for more details:
发布评论
评论(1)
您不必使 mysqld 脱机或更改端口。您可以使用
FLUSH TABLES WITH READ LOCK
来确保在您记录二进制日志位置并创建转储时不会发生写入。恢复转储通常需要很长时间,可能比创建转储所需的时间长得多。如果您的主服务器正在记录非常高的新更改率,那么是的,一旦您完成副本上的恢复并开始复制,副本可能需要一段时间才能赶上。
如果可以接受关闭 mysqld,则可以使用的替代方法是将物理数据目录从主服务器复制到副本,而不是进行转储和恢复。因此,初始化副本可以非常快,基本上只要运行 rsync 将文件从一台服务器复制到另一台服务器即可。
注意:执行此操作时,必须关闭主服务器和副本服务器上的 mysqld,否则可能会面临部分数据被缓冲且不会包含在文件副本中的风险。请记住在副本上启动 mysqld 之前检查副本上的文件所有权和权限。
您应该阅读手册中的这些部分以获取更多详细信息:
You don't necessarily have to take mysqld offline or change the port. You can use
FLUSH TABLES WITH READ LOCK
to ensure no writes happen while you're noting the binlog position and creating the dump.Restoring a dump usually takes a long time, probably a lot longer than it took to create the dump. If your master is recording a very high rate of new changes, then yes, it may take a while for the replica to catch up once you finish the restore on the replica and start replication.
An alternative you can use, if shutting down mysqld is acceptable, is to copy the physical data directory from master to replica, instead of doing the dump and restore. So initializing the replica can be very quick, basically just as long as it takes to run
rsync
to copy the files from one server to the other.note: You must shut down mysqld on master and replica as you do this, otherwise you have a risk that some of the data is buffered and won't be included in the file copy. Remember to check file ownership and permissions on the replica before starting mysqld on the replica.
You should read these sections from the manual for more details: