久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

mysql傳統主從復制的部署過程

140次閱讀
沒有評論

共計 3496 個字符,預計需要花費 9 分鐘才能閱讀完成。

這篇文章主要講解了“mysql 傳統主從復制的部署過程”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著丸趣 TV 小編的思路慢慢深入,一起來研究和學習“mysql 傳統主從復制的部署過程”吧!

部署過程

一、保證 Master 庫和 Slave 庫的數據和結構一致
可以通過 mysqldump 或者 XtraBackup 工具對 Master 庫進行全備,再把備份文件傳到 Slave 庫,Slave 庫利用改備份進行恢復,使得兩者一致。
我這里的 Slave 庫是直接復制 Master 庫生成的,所以不需要做這一步了。

二、配置兩個庫的參數文件

Master 庫需要打開二進制日志

Master 庫需要設置與 Slave 庫不同的 server-id

[root@potato data]vi /etc/my.cnf

binlog_format = mixed

server-id = 203306

log-bin = mybinlog

Slave 庫只需配置 server-id 即可

[root@tomato data]vi /etc/my.cnf

server-id = 203307

三、創建用來進行復制的用戶并且賦權

必須給予用戶 replication slave 權限,指定 Slave 庫的主機地址

點擊 (此處) 折疊或打開

root@localhost:mysql.sock  05:02:32 [(none)] grant replication slave on *.* to repl@ 192.168.161.128 identified by repl

四、讓 Slave 庫 change 到 Master 庫

查看 Master 庫此時的日志位置

點擊 (此處) 折疊或打開

root@localhost:mysql.sock  05:02:32 [(none)] show master status ;

+—————–+———-+————–+——————+——————-+

| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |

+—————–+———-+————–+——————+——————-+

| mybinlog.000004 | 331 | | | |

+—————–+———-+————–+——————+——————-+

1 row in set (0.00 sec)

從庫開始 change 到 master 庫上

點擊 (此處) 折疊或打開

root@localhost:mysql.sock  04:29:15 [(none)] change master to

 – master_host= 192.168.161.128 ,

 – master_port=3306,

 – master_user= repl ,

 – master_password= repl ,

 – master_log_file= mybinlog.000004 ,

 – master_log_pos=331;

ERROR 2006 (HY000): MySQL server has gone away

No connection. Trying to reconnect…

Connection id:    2

Current database: *** NONE ***

Query OK, 0 rows affected, 2 warnings (0.17 sec)

五、Slave 庫執行開始復制命令

點擊 (此處) 折疊或打開

root@localhost:mysql.sock  04:40:11 [(none)] start slave;

到此,主從復制就已經配置完畢了

六、對搭建的環境進行測試測試

主庫開始插入數據測試

點擊 (此處) 折疊或打開

root@localhost:mysql.sock  04:40:11 [(none)] use lala;

root@localhost:mysql.sock  04:51:23 [(lala)] create table haha(id int);

root@localhost:mysql.sock  04:51:23 [(lala)] insert into haha values(1);

從庫是否接受到數據

點擊 (此處) 折疊或打開

root@localhost:mysql.sock  04:52:55 [(none)] select * from lala.haha;

+——+

| id |

+——+

| 1 |

+——+

1 row in set (0.00 sec)

查看 Slave 狀態

點擊 (此處) 折疊或打開

root@localhost:mysql.sock  04:57:23 [(none)] show slave status\G

*************************** 1. row ***************************

 Slave_IO_State: Waiting for master to send event

 Master_Host: 192.168.161.128

 Master_User: repl

 Master_Port: 3306

 Connect_Retry: 60

 Master_Log_File: mybinlog.000004

 Read_Master_Log_Pos: 620

 Relay_Log_File: mysql-relay-bin.000003

 Relay_Log_Pos: 571

 Relay_Master_Log_File: mybinlog.000004

 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: 620

 Relay_Log_Space: 744

 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: 203306

 Master_UUID: af3609cd-b426-11e6-a997-000c29d55626

 Master_Info_File: /data/mysql/mytest_3306/data/master.info

 SQL_Delay: 0

 SQL_Remaining_Delay: NULL

 Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it

 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: 0

1 row in set (0.00 sec)

主從復制部署測試成功

感謝各位的閱讀,以上就是“mysql 傳統主從復制的部署過程”的內容了,經過本文的學習后,相信大家對 mysql 傳統主從復制的部署過程這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是丸趣 TV,丸趣 TV 小編將為大家推送更多相關知識點的文章,歡迎關注!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-08-01發表,共計3496字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 竹溪县| 子长县| 巴里| 永平县| 健康| 三台县| 庄浪县| 澎湖县| 娄底市| 同江市| 遂宁市| 临清市| 洛扎县| 嘉定区| 平塘县| 农安县| 渝北区| 大同县| 察雅县| 平湖市| 察哈| 大田县| 福鼎市| 米脂县| 卓资县| 沅陵县| 建水县| 团风县| 南平市| 武功县| 富阳市| 沧州市| 万荣县| 武城县| 正蓝旗| 衡南县| 马山县| 鄢陵县| 抚宁县| 乐亭县| 偃师市|