使用现有主服务器创建新的从服务器 - 初始数据库创建过程是什么样的?

发布于 2024-12-29 12:16:44 字数 1459 浏览 1 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

塔塔猫 2025-01-05 12:16:44

您不必使 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:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文