五月综合激情婷婷六月,日韩欧美国产一区不卡,他扒开我内裤强吻我下面视频 ,无套内射无矿码免费看黄,天天躁,日日躁,狠狠躁

新聞動態(tài)

MySQL5.7.18主從復(fù)制搭建(一主一從)教程詳解

發(fā)布日期:2022-04-05 13:57 | 文章來源:源碼中國

一、復(fù)制原理

主服務(wù)器將更新寫入二進(jìn)制日志文件,并維護(hù)文件的一個索引以跟蹤日志循環(huán)。這些日志可以記錄發(fā)送到從服務(wù)器的更新.當(dāng)一個從服務(wù)器連接主服務(wù)器時,它通知主服務(wù)器從服務(wù)器在日志中讀取的最后一次成功更新的位置。從服務(wù)器接收從那時起發(fā)生的任何更新,然后封鎖并等待主服務(wù)器通知新的更新。

MySQL使用3個線程來執(zhí)行復(fù)制功能(其中1個在主服務(wù)器上,另兩個在從服務(wù)器上。當(dāng)發(fā)出START SLAVE時,從服務(wù)器創(chuàng)建一個I/O線程,以連接主服務(wù)器并讓它發(fā)送記錄在其二進(jìn)制日志中的語句。主服務(wù)器創(chuàng)建一個線程將二進(jìn)制日志中的內(nèi)容發(fā)送到從服務(wù)器。

該線程為主服務(wù)器上的Binlog Dump線程。從服務(wù)器I/O線程讀取主服務(wù)器Binlog Dump線程發(fā)送的內(nèi)容并將該數(shù)據(jù)拷貝到從服務(wù)器數(shù)據(jù)目錄中的本地文件中,即中繼日志。第3個線程是SQL線程,是從服務(wù)器創(chuàng)建用于讀取中繼日志并執(zhí)行日志中包含的更新。

二、服務(wù)器準(zhǔn)備

操作系統(tǒng)版本:Red Hat Enterprise Linux Server release 6.7 (Santiago)

Master(主) ip:172.16.115.245 主機(jī)名稱:mysql2 server_id:245

Slave(從) ip:172.16.115.247 主機(jī)名稱:mysql3 server_id:247

主從服務(wù)器上都已安裝MySQL5.7.18

三、主從復(fù)制實(shí)施細(xì)節(jié)

1.主服務(wù)器上為服務(wù)器設(shè)置一個連接賬戶并授予REPLICATION SLAVE權(quán)限。

GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY 'repl@20170509';

2.修改master配置文件my.cnf

server-id = 245
log_bin = /data/mysqllog/3306/bin_log/binlog

這兩個值必須設(shè)置,設(shè)置好之后,重啟MySQL。

3.備份master上一份完整的數(shù)據(jù)

mysqldump -uroot -p'密碼' --master-data=2 --single-transaction -R --triggers -A > /backup/all.sql

說明:

--master-data=2代表備份時刻記錄master的Binlog位置和Position
--single-transaction意思是獲取一致性快照
-R意思是備份存儲過程和函數(shù)
--triggres的意思是備份觸發(fā)器
-A代表備份所有的庫

4.查看主庫備份時的binlog名稱和位置

SHOW MASTER STATUS;
mysql> SHOW MASTER STATUS;
+---------------+----------+--------------+------------------+-------------------+
| File     | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+---------------+----------+--------------+------------------+-------------------+
| binlog.000004 | 79394496 |       |         |          |
+---------------+----------+--------------+------------------+-------------------+

或者到剛才備份的數(shù)據(jù)庫文件中看:vi all.sql

5.修改slave庫配置文件my.cnf

server-id = 247 (唯一,不能與主庫一樣,一般設(shè)為服務(wù)器IP后3位)
log_bin = /data/mysql/logdir/3306/bin_log/binlog
innodb_file_per_table = ON
skip_name_resolve = ON
relay_log = /data/mysql/logdir/3306/relay_log/relay.log
binlog-format = row
log-slave-updates = true

read_only=ON (只讀模式)

設(shè)置完之后,重啟MySQL。

6.在slave服務(wù)器上恢復(fù)master備份

mysql -u root -p'密碼' < all.sql

7.停止從庫,并配置主從參數(shù),打開從庫。

mysql> stop slave; #暫停從庫
mysql>CHANGE MASTER TO MASTER_HOST='172.16.115.245',MASTER_USER='repl', MASTER_PASSWORD='repl@20170509',MASTER_LOG_FILE='binlog.000004',MASTER_LOG_POS=154;
mysql> start slave; #啟動復(fù)制
mysql> show slave status\G
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 172.16.115.245
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000004
Read_Master_Log_Pos: 104634190
Relay_Log_File: relay.000003
Relay_Log_Pos: 104632819
Relay_Master_Log_File: binlog.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: 104634190
Relay_Log_Space: 104634713
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: 245
Master_UUID: 4f545573-3170-11e7-b903-000c29462d8c
Master_Info_File: /data/mysql/datadir/3306/data/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: 
Executed_Gtid_Set: 
Auto_Position: 0
Replicate_Rewrite_DB: 
Channel_Name: 
Master_TLS_Version: 

8.查看master、slave相關(guān)進(jìn)程

master Binlog Dump線程:

mysql> SHOW PROCESSLIST \G
*************************** 1. row ***************************
Id: 13
User: repl
Host: 172.16.115.247:44602
db: NULL
Command: Binlog Dump
Time: 76514
State: Master has sent all binlog to slave; waiting for more updates
Info: NULL

slave IO/SQL線程:

mysql> SHOW PROCESSLIST \G
*************************** 1. row ***************************
Id: 10
User: system user
Host: 
db: NULL
Command: Connect
Time: 81148
State: Waiting for master to send event
Info: NULL
*************************** 2. row ***************************
Id: 12
User: system user
Host: 
db: NULL
Command: Connect
Time: 5
State: Reading event from the relay log
Info: NULL

9.至此,主從配置已經(jīng)完成,可以到master服務(wù)器上創(chuàng)建數(shù)據(jù)庫、表等操作,看slave數(shù)據(jù)庫是否同步!

總結(jié)

以上所述是小編給大家介紹的MySQL5.7.18主從復(fù)制搭建(一主一從)教程詳解,希望對大家有所幫助,如果大家有任何疑問歡迎給我留言,小編會及時回復(fù)大家的!

香港快速服務(wù)器

版權(quán)聲明:本站文章來源標(biāo)注為YINGSOO的內(nèi)容版權(quán)均為本站所有,歡迎引用、轉(zhuǎn)載,請保持原文完整并注明來源及原文鏈接。禁止復(fù)制或仿造本網(wǎng)站,禁止在非maisonbaluchon.cn所屬的服務(wù)器上建立鏡像,否則將依法追究法律責(zé)任。本站部分內(nèi)容來源于網(wǎng)友推薦、互聯(lián)網(wǎng)收集整理而來,僅供學(xué)習(xí)參考,不代表本站立場,如有內(nèi)容涉嫌侵權(quán),請聯(lián)系alex-e#qq.com處理。

實(shí)時開通

自選配置、實(shí)時開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

在線客服:7*24小時在線

客服
熱線

400-630-3752
7*24小時客服服務(wù)熱線

關(guān)注
微信

關(guān)注官方微信
頂部