一篇搞懂MySQL 8.0 Clone技术在线搭建主从复制全过程

本文将通过Clone来实现一个远程从库的篇搞搭建:环境如下

Mater: 192.168.3.133 port:3307 doner 捐赠者

Slave: 192.168.3.134 port:3307 recipient 接受者

第一步:两台机器MySQL分别进行初始化安装

进入MySQL软件目录进行初始化安装并修改密码:(MySQL8.0.19 下载解压步骤省略) 

[root@mgr2 bin]#cd /zcloud/db/abcMgr/abcMgr02/mysql/bin  [root@mgr2 bin]# ./mysqld --initialize --user=mysql  [root@mgr2 bin]# ./mysqld_safe --user=mysql &  [1] 19556  [root@mgr2 bin]# 2020-03-12T01:32:26.503048Z mysqld_safe Logging to ‘/rock/mysqldata/error.log’.  2020-03-12T01:32:26.536292Z mysqld_safe Starting mysqld daemon with databases from /rock/mysqldata  [root@mgr2 bin]#  [root@mgr2 bin]# mysql -uroot -p -P3307  Enter password:  Welcome to the MySQL monitor. Commands end with ; or \g.  Your MySQL connection id is 8  Server version: 8.0.19  Copyright © 2000, 2019, Oracle and/or its affiliates. All rights reserved.  Oracle is a registered trademark of Oracle Corporation and/or its  affiliates. Other names may be trademarks of their respective  owners.  Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.  root@localhost:(none) 09:33:06 >alter user user() identified by ‘root1234’;  Query OK, 0 rows affected (0.00 sec) root@localhost:(none) 09:33:26 >flush privileges;  Query OK, 0 rows affected (0.00 sec)  root@localhost:(none) 09:33:31 >exit  Bye

第二步:doner节点192.168.3.133相关操作

–创建用户 

root@localhost:(none) 10:07:05 >create user ‘donor_user’@‘192.168.3.134’ identified by ‘password’;  Query OK, 0 rows affected (0.00 sec)  root@localhost:(none) 10:07:07 >grant backup_admin on . to ‘donor_user’@‘192.168.3.134’;  Query OK, 0 rows affected (0.01 sec)

–安装clone插件 

root@localhost:(none) 10:23:16 >install plugin clone soname ‘mysql_clone.so’;  Query OK, 0 rows affected (0.01 sec) 

第三步:recipient节点192.168.3.134相关操作

–创建用户(也可以不创建用户,用root直接操作) 

mysql> create user ‘recipient_user’@‘192.168.3.134’ identified by ‘password’;

–安装clone插件 

mysql> grant clone_admin on . to ‘recipient_user’@‘192.168.3.134’; 

–设置参数clone_valid_donor_list 

root@localhost:(none) 03:28:40 >set global clone_valid_donor_list=‘192.168.3.133:3307’;  Query OK,懂M搭建 0 rows affected (0.00 sec) 

–换成recipient_user’@‘192.168.3.134’ 用户登陆,云南idc服务商执行clone语句(这里其实可以用本地root用户直接进行登录操作)

[root@mgr3 bin]# mysql -urecipient_user -ppassword -P3307 -h192.168.3.134  recipient_user@192.168.3.134:(none) 03:39:46 >clone instance from ‘donor_user’@‘192.168.3.133’:3307 identified by ‘password’;  Query OK,术线 0 rows affected (2.34 sec)  recipient_user@192.168.3.134:(none) 03:39:57 >Restarting mysqld…  2020-03-12T07:40:01.285267Z mysqld_safe Number of processes running now: 0  2020-03-12T07:40:01.290169Z mysqld_safe mysqld restarted

至此,远程数据的网站模板复制克隆已经完成了。

通过查询两张表来监控一下克隆的站群服务器全过进度和结果状态:

–查看clone进度和状态 

root@localhost:(none) 03:34:49 >SELECT * FROM performance_schema.clone_progress;  ±-----±----------±----------±---------------------------±---------------------------±--------±----------±----------±----------±-----------±--------------+ | ID | STAGE | STATE | BEGIN_TIME | END_TIME | THREADS | ESTIMATE | DATA | NETWORK | DATA_SPEED | NETWORK_SPEED |  ±-----±----------±----------±---------------------------±---------------------------±--------±----------±----------±----------±-----------±--------------+ | 1 | DROP DATA | Completed | 2020-03-12 15:29:15.385694 | 2020-03-12 15:29:15.634609 | 1 | 0 | 0 | 0 | 0 | 0 |  | 1 | FILE COPY | Completed | 2020-03-12 15:29:15.634765 | 2020-03-12 15:29:17.452961 | 1 | 465800520 | 465800520 | 465833356 | 0 | 0 |  | 1 | PAGE COPY | Completed | 2020-03-12 15:29:17.453144 | 2020-03-12 15:29:17.554224 | 1 | 0 | 0 | 99 | 0 | 0 |  | 1 | REDO COPY | Completed | 2020-03-12 15:29:17.554413 | 2020-03-12 15:29:17.654430 | 1 | 2560 | 2560 | 3031 | 0 | 0 |  | 1 | FILE SYNC | Completed | 2020-03-12 15:29:17.654596 | 2020-03-12 15:29:17.730172 | 1 | 0 | 0 | 0 | 0 | 0 |  | 1 | RESTART | Completed | 2020-03-12 15:29:17.730172 | 2020-03-12 15:29:22.160372 | 0 | 0 | 0 | 0 | 0 | 0 |  | 1 | RECOVERY | Completed | 2020-03-12 15:29:22.160372 | 2020-03-12 15:29:22.478889 | 0 | 0 | 0 | 0 | 0 | 0 |  ±-----±----------±----------±---------------------------±---------------------------±--------±----------±----------±----------±-----------±--------------+  7 rows in set (0.00 sec)  root@localhost:(none) 03:34:52 >SELECT * FROM performance_schema.clone_status\G  
滇ICP备2023000592号-31