当前位置: 首页 > 科技观察

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

时间:2023-03-15 08:25:36 科技观察

一文看懂MySQL8.0Clone技术在线主从复制全过程收件人:3307第一步:分别在两台机器上进行MySQL初始安装进入初始安装的MySQL软件目录,修改密码:(MySQL8.0)0.19下载解压步骤略)[root@mgr2bin]#cd/zcloud/db/abcMgr/abcMgr02/mysql/bin[root@mgr2bin]#./mysqld--initialize--user=mysql[root@mgr2bin]#。/mysqld_safe--user=mysql&[1]19556[root@mgr2bin]#2020-03-12T01:32:26.503048Zmysqld_safeLoggingto'/rock/mysqldata/error.log'.2020-03-12T01:32:26.536292Zmysqld_safeStartingmysqlddaemonwithdatabasesfrom/rock/mysqldata[root@mgr2bin]#[root@mgr2bin]#mysql-uroot-pP3307Enterpassword:WelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis8Serverversion:8.0.19Copyright?2000,2019,Oracleand/oritsaffiliates.Allrightsreserved.OracleisaregisteredtrademarkofOracleitresCorporatesand/or\g.YourMySQLconnectionidis8Serverversion:8.0.19Copyright?2000,2019,Oracleand/oritsaffiliates.Allrightsreserved.Oracle是Oracle的注册商标。ectiveowners.Type'help;'or'\h'forhelp.Type'\c’toclearthecurrentinputstatement.root@localhost:(none)09:33:06>alteruseruser()identifiedby'root1234';QueryOK,0rowsaffected(0.00sec)root@localhost:(none)09:33:26>flushprivileges;QueryOK,0rowsaffected(0.00sec)root@localhost:(none)09:33:31>exitByeStep2:Doner节点192.168.3.133相关操作-创建用户root@localhost:(none)10:07:05>createuser'donor_user'@'192.168.3.134'identifiedby'password';QueryOK,0rowsaffected(0.00sec)root@localhost:(none)10:07:07>grantbackup_adminon.to'donor_user'@'192.168.3.134';QueryOK,0rowsaffected(0.01sec)–安装克隆插件root@localhost:(none)10:23:16>installpluginclonename'mysql_clone.so';QueryOK,0rowsaffected(0.01sec)第三步:Recipient节点192.168.3.134相关操作-创建用户(或者不创建User,直接用root操作)mysql>createuser'recipient_user'@'192.168.3.134'identifiedby'password';–安装克隆插件mysql>grantclone_adminon.to&lsqu;recipient_user'@'192.168.3.134';–设置参数clone_valid_donor_listroot@localhost:(none)03:28:40>setglobalclone_valid_donor_list='192.168.3.133:3307';QueryOK,0rowsaffected(0.00sec)–用户替换为@recipient_''192.168.3.134'用户登录,执行clone语句(其实可以使用本地root用户直接登录)[root@mgr3bin]#mysql-urecipient_user-ppassword-P3307-h192.168.3.134recipient_user@192.168.3.134:(无)03:39:46>从'donor_user'@'192.168.3.133':3307identifiedby'password'克隆实例;QueryOK,0rowsaffected(2.34sec)recipient_user@192.168.3.134:(none)03:39:57>Restartingmysqld…2020-03-12T07:40:01.285267Zmysqld_safeNumberofprocessesrunningnow:02020-03-12T07:40:01.290169Zmysqld_safemysqldrestarted至此远程数据克隆完成通过查询两个表监控克隆的进度和结果状态:–查看克隆的进度和状态root@localhost:(none)03:34:49>SELECT*FROMperformance_schema.clone_progress;±-----±-----------±------------±----------------------------±---------------------------±--------±------------±-----------±------------±------------±------------+|ID|STAGE|STATE|BEGIN_TIME|END_TIME|THREADS|ESTIMATE|DATA|NETWORK|DATA_SPEED|NETWORK_SPEED|±-----±--------±------------±----------------------------±-----------------------------±-------±------------±------------±------------±-------------±------------+|1|DROPDATA|已完成|2020-03-1215:29:15.385694|2020-03-1215:29:15.634609|1|0|0|0|0|0||1|文件复制|完成|2020-03-1215:29:15.634765|2020-03-1215:29:17.452961|1|465800520|465800520|465833356|0|0||1|页面复制|完成|2020-03-1215:29:17.453144|2020-03-1215:29:17.554224|1|0|0|99|0|0||1|REDOCOPY|已完成|2020-03-1215:29:17.554413|2020-03-1215:29:17.654430|1|2560|2560|3031|0|0||1|FILESYNC|已完成|2020-03-1215:29:17.654596|2020-03-1215:29:17.730172|1|0|0|0|0|0||1|重启|已完成|2020-03-1215:29:17.730172|2020-03-1215:29:22.160372|0|0|0|0|0|0||1|恢复|完成|2020-03-1215:29:22.160372|2020-03-1215:29:22.478889|0|0|0|0|0|0|±-----±---------±---------±---------------------------±----------------------------±--------±---------±------------±------------±------------±--------------+7rowsinset(0.00sec)root@localhost:(none)03:34:52>SELECT*FROMperformance_schema.clone_status\G***************************1.row***************************ID:1PID:0STATE:CompletedBEGIN_TIME:2020-03-1215:29:15.385END_TIME:2020-03-1215:29:22.479SOURCE:192.168.3.133:3307DESTINATION:LOCALINSTANCEERROR_NO:0ERROR_MESSAGE:BINLOG_FILE:mysql-bin.000002BINLOG_POSITION:421GTID_7EXECUTED5bf2f-6401-11ea-8995-000c29db65a6:11rowinset(0.00sec)–在主存储库133上创建复制帐户:root@localhost:(none)04:12:23>createuserrepl@'192.168.3.%'identifiedby'repl';QueryOK,0rowsaffected(0.00sec)root@localhost:(none)04:13:03>grantallon.torepl@'192.168.3.%';QueryOK,0rowsaffected(0.00sec)–从库复制步骤134完成of:root@localhost:(none)04:16:09>changemastertomaster_host='192.168.3.133',master_port=3307,master_user='repl',master_password='repl',master_auto_position=1;QueryOK,0rowsaffected,2warnings(0.00sec)root@localhost:(none)04:17:32>startslave;QueryOK,0rowsaffected(0.00sec)root@localhost:(none)04:17:35>showslavestatus\G****************************1.row******************************Slave_IO_State:WaitingformastertosendeventMaster_Host:192.168.3.133Master_User:replMaster_Port:3307Connect_Retry:60Master_Log_File:mysql-bin.000002Read_Master_Log_Pos:1193Relay_Log_File:mgr3-relay-bin.000002Relay_Log_Pos:904Relay_Master_Log_File:mysql-bin.000002Slave_IO_Running:YesSlave_SQL_Running:YesReplicate_Do_DB:Replicate_Ignore_DB:Replicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table:Last_Errno:0Last_Error:Skip_Counter:0Exec_Master_Log_Pos:1193Relay_Log_Space:1103Until_Condition:NoneUntil_Log_File:Until_Log_Pos:0Master_SSL_Allowed:NoMaster_SSL_CA_File:Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher:Master_SSL_Key:Seconds_Behind_Master:0Master_SSL_Verify_Server_Cert:NoLast_IO_Errno:0Last_IO_Error:Last_SQL_Errno:0Last_SQL_Error:Replicate_Ignore_Server_Ids:Master_Server_Id:207Master_UUID:3e75bf2f-6401-11ea-8995-000c29db65a6Master_Info_File:mysql.slave_master_infoSQL_Delay:0SQL_Remaining_Delay:NULLSlave_SQL_Running_State:Slavehasreadallrelaylog;waitingformoreupdatesMaster_Retry_Count:86400Master_Bind:Last_IO_Error_Timestamp:Last_SQL_Error_Timestamp:Master_SSL_Crl:Master_SSL_Crlpath:Retrieved_Gtid_Set:3e75bf2f-6401-11ea-8995-000c29db65a6:3-4Executed_Gtid_Set:3e75bf2f-6401-11ea-8995-000c29db65a6:1-4Auto_Position:1Replicate_Rewrite_DB:Channel_Name:Master_TLS_Version:Master_public_key_path:Get_master_public_key:0Network_Namespace:1rowinset(0.00sec)至此远程从库通过clone插件方法已经搭建成功,非常简单,速度也很快。它不需要mysqldump或xtrabackup。在线搭建成功,速度非常快。以后8.0可以考虑这种方便的方法。最后列出克隆技术的局限性:版本大于等于8.0.17,不支持跨版本。两台机器具有相同的操作系统OS。两个MySQL实例具有相同的innodb_page_size和innodb_data_file_path(ibdata文件名)。同一时间只允许有一个克隆任务存在。接受者需要设置变量clone_valid_donor_listmax_allowed_pa??cket大于2Mdoner的undo表空间文件名不能重复。my.cnf文件不会被克隆。binlog不会被克隆。仅支持innodb引擎。