MySQL 5.7 基於GTID搭建主從複製
MySQL 5.7 基於GTID搭建主從複製
一、搭建過程
1.1 準備三個MySQL例項
mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/3307/data/ mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/3308/data/ mysqld --initialize-insecure --user=mysql --basedir=/usr/local/mysql --datadir=/mysql/3309/data/
1.2 server_id, server_uuid 不同
mysql -uroot -p123 -e "select @@server_id" mysql -uroot -p123 -e "select @@server_uuid"
1.3 gtid_mode 是否開啟:
mysql -uroot -p123 -e "select @@gtid_mode" mysql -uroot -p123 -e "select @@server_gtid" vi 330{7..9}/my.cnf gtid_mode=ON enforce_gtid_consistency=ON log_slave_updates=ON
1.4 確認binlog開啟
mysql -uroot -p123 -e "select @@log_bin"
1.5 備份主庫資料到從庫透過遠端方式
mysqldump -uroot -p123 -h 192.168.84.30 -P 3307 > /tmp/full.sql
1.6 恢復資料
mysql> source /tmp/full.sql
1.7 主庫建立複製使用者
grant replication slave on *.* to repl@'192.168.84.30' identified by '123';
1.8 從庫啟動複製
幫助: mysql> help change master to ...... 找到配置模板: CHANGE MASTER TO MASTER_HOST='master2.example.com', MASTER_USER='replication', MASTER_PASSWORD='password', MASTER_PORT=3306, MASTER_LOG_FILE='master2-bin.001', MASTER_LOG_POS=4, MASTER_CONNECT_RETRY=10; 3308,3309使用如下配置: CHANGE MASTER TO MASTER_HOST='192.168.84.30', MASTER_USER='repl', MASTER_PASSWORD='123', MASTER_PORT=3307, master_auto_position=1; 開始配置3308 mysql> CHANGE MASTER TO -> MASTER_HOST='192.168.84.30', -> MASTER_USER='repl', -> MASTER_PASSWORD='123', -> MASTER_PORT=3307, -> master_auto_position=1; Query OK, 0 rows affected, 2 warnings (0.00 sec) 開始配置3309 mysql> CHANGE MASTER TO -> MASTER_HOST='192.168.84.30', -> MASTER_USER='repl', -> MASTER_PASSWORD='123', -> MASTER_PORT=3307, -> master_auto_position=1; Query OK, 0 rows affected, 2 warnings (0.00 sec)
1.9 檢視狀態:
mysql> show slave status \G; 檢視slave狀態 mysql> show slave status \G; *************************** 1. row *************************** Slave_IO_State: Master_Host: 192.168.84.30 Master_User: repl Master_Port: 3307 Connect_Retry: 60 Master_Log_File: Read_Master_Log_Pos: 4 Relay_Log_File: open_source-relay-bin.000001 Relay_Log_Pos: 4 Relay_Master_Log_File: Slave_IO_Running: No Slave_SQL_Running: No 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: 0 Relay_Log_Space: 154 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: NULL 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: 0 Master_UUID: Master_Info_File: /mysql/3308/data/master.info SQL_Delay: 0 SQL_Remaining_Delay: NULL Slave_SQL_Running_State: Master_Retry_Count: 86400 Master_Bind: Last_IO_Error_Timestamp: Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: Auto_Position: 1 Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: 1 row in set (0.00 sec) ERROR: No query specified
2.0 啟動和關閉複製:
start slave; stop slave;
備註:5.7 MGR 新出的亮點,8.0.17建議用MGR
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/20674423/viewspace-2679320/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- MySQL 5.7基於GTID的主從複製MySql
- Mysql 基於GTID主從複製MySql
- mysql之 mysql 5.6不停機主從搭建(一主一從基於GTID複製)MySql
- mysql之 MySQL 主從基於 GTID 複製原理概述MySql
- 基於GTID搭建主從MySQLMySql
- mysql 5.7 主從複製搭建及原理MySql
- MySQL5.7主從複製-半同步複製搭建MySql
- MySQL 5.7 用mysqldump搭建gtid主從MySql
- MySQL 5.7 用xtrabackup搭建gtid主從MySql
- MySQL主從複製之GTID複製MySql
- mysql5.7主從複製,主主複製MySql
- Mysql 8.4.0 結合 Docker 搭建GTID主從複製,以及傳統主從複製MySqlDocker
- mysql GTID 主從複製概述MySql
- MysqL主從複製_模式之GTID複製MySql模式
- MySQL 5.7 使用GTID方式搭建複製環境MySql
- 【MySQL】主從GTID複製修復MySql
- mysql 5.7 GTID主從配置MySql
- mysql 5.7 多主一從的多源複製搭建MySql
- 基於 Docker 的 MySQL 主從複製搭建(真正弄懂)DockerMySql
- MySQL 主從複製搭建,基於日誌(binlog)MySql
- MySQL 5.7傳統複製到GTID線上切換(一主一從)MySql
- MySQL5.7主從複製教程MySql
- mysql主從複製搭建MySql
- MySQL 5.6 建立GTID主從複製 (GTID-based Replication)MySql
- Mysql基於GTID的複製模式MySql模式
- MYSQL主從複製的搭建MySql
- 基於 Docker 的 MySQL 主從複製搭建及原理(真正弄懂)DockerMySql
- MySQL 5.7的安裝及主從複製(主從同步)MySql主從同步
- mysql之 mysql 5.6不停機主從搭建(一主一從基於日誌點複製)MySql
- mysql 基於日誌的主從複製MySql
- MySQL基於binlog主從複製配置MySql
- mysql5.7 GTID 主從複製模式-增加新的slave1(好文章!!)MySql模式
- MySQL8.0輕鬆搞定GTID主從複製MySql
- Mysql主從複製原理及搭建MySql
- 簡單搭建MySQL主從複製MySql
- mysql之 MySQL 主從基於position複製原理概述MySql
- MySQL(14)---Docker搭建MySQL主從複製(一主一從)MySqlDocker
- MySQL 複製全解析 Part 9 一步步搭建基於GTID的MySQL複製MySql