使用MySQL8.0 clone技術線上搭建主從複製
使用MySQL8.0 clone技術線上搭建主從複製
MySQL從8.0.17開始新增了克隆clone技術,可以線上進行MySQL的本地克隆或遠端克隆,從此搭建從庫可以不再需要備份工具來實現了,下面將通過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, 0 rows affected (0.00 sec)
–換成recipient_user’@‘192.168.3.134’ 使用者登陸,執行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 *************************** 1. row *************************** ID: 1 PID: 0 STATE: Completed BEGIN_TIME: 2020-03-12 15:29:15.385 END_TIME: 2020-03-12 15:29:22.479 SOURCE: 192.168.3.133:3307 DESTINATION: LOCAL INSTANCE ERROR_NO: 0 ERROR_MESSAGE: BINLOG_FILE: mysql-bin.000002 BINLOG_POSITION: 421 GTID_EXECUTED: 3e75bf2f-6401-11ea-8995-000c29db65a6:1 1 row in set (0.00 sec) –在主庫133上建立複製賬號: root@localhost:(none) 04:12:23 >create user repl@‘192.168.3.%’ identified by ‘repl’; Query OK, 0 rows affected (0.00 sec) root@localhost:(none) 04:13:03 >grant all on . to repl@‘192.168.3.%’; Query OK, 0 rows affected (0.00 sec) –在從庫134上進行復制步驟的完成: root@localhost:(none) 04:16:09 >change master to master_host=‘192.168.3.133’,master_port=3307,master_user=‘repl’,master_password=‘repl’,master_auto_position=1; Query OK, 0 rows affected, 2 warnings (0.00 sec) root@localhost:(none) 04:17:32 >start slave; Query OK, 0 rows affected (0.00 sec) root@localhost:(none) 04:17:35 >show slave status\G *************************** 1. row *************************** Slave_IO_State: Waiting for master to send event Master_Host: 192.168.3.133 Master_User: repl Master_Port: 3307 Connect_Retry: 60 Master_Log_File: mysql-bin.000002 Read_Master_Log_Pos: 1193 Relay_Log_File: mgr3-relay-bin.000002 Relay_Log_Pos: 904 Relay_Master_Log_File: mysql-bin.000002 Slave_IO_Running: Yes Slave_SQL_Running: Yes Replicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0 Last_Error: Skip_Counter: 0 Exec_Master_Log_Pos: 1193 Relay_Log_Space: 1103 Until_Condition: None Until_Log_File: Until_Log_Pos: 0 Master_SSL_Allowed: No Master_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0 Master_SSL_Verify_Server_Cert: No Last_IO_Errno: 0 Last_IO_Error: Last_SQL_Errno: 0 Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 207 Master_UUID: 3e75bf2f-6401-11ea-8995-000c29db65a6 Master_Info_File: mysql.slave_master_info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: 3e75bf2f-6401-11ea-8995-000c29db65a6:3-4 Executed_Gtid_Set: 3e75bf2f-6401-11ea-8995-000c29db65a6:1-4 Auto_Position: 1 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: Master_public_key_path: Get_master_public_key: 0 Network_Namespace: 1 row in set (0.00 sec)
至此遠端從庫通過clone外掛的方式搭建成功了,非常簡單也非常快速,不需要mysqldump也不需要xtrabackup,線上搭建成功,非常快,以後用8.0可以考慮這種便捷的方式了。
最後將clone技術的限制條件列出:
- 版本大於等於8.0.17且不支援跨版本
- 兩臺機器具有相同的作業系統OS
- 兩臺MySQL例項具體相同的 innodb_page_size 和 innodb_data_file_path(ibdata檔名)
- 同一時刻僅僅允許有一個克隆任務存在
- recipient 需要設定變數clone_valid_donor_list
- max_allowed_packet 大於2M
- doner的undo表空間檔名稱不能重複
- 不會克隆my.cnf檔案
- 不會克隆binlog
- 僅僅支援innodb引擎
About Me
........................................................................................................................ ● 本文作者:小麥苗,部分內容整理自網路,若有侵權請聯絡小麥苗刪除 ● 本文在個人微 信公眾號( DB寶)上有同步更新 ● QQ群號: 230161599 、618766405,微信群私聊 ● 個人QQ號(646634621),微 訊號(db_bao),註明新增緣由 ● 於 2020年11月完成 ● 最新修改時間:2020年11月 ● 版權所有,歡迎分享本文,轉載請保留出處 ........................................................................................................................ ● 小麥苗的微店: https://weidian.com/s/793741433?wfr=c&ifr=shopdetail ● 小麥苗出版的資料庫類叢書: http://blog.itpub.net/26736162/viewspace-2142121/ ● 小麥苗OCP、OCM、高可用、DBA學習班: http://blog.itpub.net/26736162/viewspace-2148098/ ● 資料庫筆試面試題庫及解答: http://blog.itpub.net/26736162/viewspace-2134706/ ........................................................................................................................ 請掃描下面的二維碼來關注小麥苗的微 信公眾號( DB寶)及QQ群(230161599、618766405)、新增小麥苗微 信(db_bao), 學習最實用的資料庫技術。
........................................................................................................................ |
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/26736162/viewspace-2731779/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL8.0主從複製MySql
- Redis 主從複製技術原理Redis
- Innobackupex實現mysql線上搭建master-slave主從複製MySqlAST
- mysql主從複製搭建MySql
- MySQL8.0輕鬆搞定GTID主從複製MySql
- MySQL5.7主從複製-半同步複製搭建MySql
- 簡單搭建MySQL主從複製MySql
- Mysql主從複製原理及搭建MySql
- MySQL8.0主從複製命中1032案例分析MySql
- Mysql 8.4.0 結合 Docker 搭建GTID主從複製,以及傳統主從複製MySqlDocker
- MySQL8.0輕鬆搞定GTID主主複製MySql
- Centos8.3、mysql8.0主從複製實戰記錄CentOSMySql
- MySQL(14)---Docker搭建MySQL主從複製(一主一從)MySqlDocker
- mysql主從複製的理解和搭建MySql
- docker-compase搭建mysql主從複製DockerMySql
- Redis搭建主從複製、哨兵叢集Redis
- mysql 5.7 主從複製搭建及原理MySql
- mysql5.7主從複製,主主複製MySql
- MySQL-主從複製之搭建主資料庫MySql資料庫
- 主從複製
- Docker Compose搭建MySQL主從複製叢集DockerMySql
- MongoDB日常運維-03主從複製搭建MongoDB運維
- MySQL 5.7 基於GTID搭建主從複製MySql
- MySQL-主從複製之搭建從資料庫MySql資料庫
- mysql複製--主從複製配置MySql
- Redis多例項及主從複製環境搭建Redis
- Redis:主從複製Redis
- Redis - 主從複製Redis
- MySQL主從複製MySql
- Redis主從複製Redis
- MySQL主從複製之GTID複製MySql
- MySQL 5.7傳統複製到GTID線上切換(一主一從)MySql
- 阿里雲RDS與ECS自建庫搭建主從複製阿里
- 基於 Docker 的 MySQL 主從複製搭建(真正弄懂)DockerMySql
- 主從複製是啥或者主從複製的原理是什麼?
- MySQL主從複製之半同步複製MySql
- MySQL主從複製之非同步複製MySql非同步
- Windows 環境下,MySQL 的主從複製和主主複製WindowsMySql