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

新聞動態(tài)

MySQL 雙向備份的實現(xiàn)方法

發(fā)布日期:2022-03-13 08:02 | 文章來源:CSDN

MySQL 雙向備份也被稱為 主主備份 ,即兩個 MySQL 服務(wù)都是 Master,其中任意一個服務(wù)又是另一個服務(wù)的 Slave。

準(zhǔn)備

服務(wù)器

MySQL服務(wù)器 版本 IP地址
masterA 5.6.41 192.168.1.201
masterB 5.6.41 192.168.1.202

注:備份的 MySQL 服務(wù)器版本盡量保持一致,不同的版本可能二進(jìn)制日志格式不兼容。

具體操作

注意

操作過程中注意兩邊數(shù)據(jù)的一致?。?!

masterA 配置

my.cnf

[mysqld]
# 服務(wù)器唯一標(biāo)識
server-id=1
# 二進(jìn)制日志文件名
log-bin=mysql-bin
# 需要備份的數(shù)據(jù)庫,多個數(shù)據(jù)庫用 , 分隔
binlog-do-db=piumnl
# 需要復(fù)制的數(shù)據(jù)庫,多個數(shù)據(jù)庫用 , 分隔
replicate-do-db=piumnl
# 中繼日志文件名
relay_log=mysqld-relay-bin
# 手動啟動同步服務(wù),避免突然宕機導(dǎo)致的數(shù)據(jù)日志不同步
skip-slave-start=ON
# 互為主從需要加入這一行
log-slave-updates=ON
# 禁用符號鏈接,防止安全風(fēng)險,可不加
symbolic-links=0
# 可不加
# resolve - [Warning] Slave SQL: If a crash happens this configuration does not guarantee that the relay log info will be consistent, Error_code: 0
master-info-repository=table
relay-log-info-repository=table
relay-log-recovery=1
# 可不加
# 禁用 dns 解析,會使授權(quán)時使用的域名無效
skip-host-cache
skip-name-resolve
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

masterB 配置

my.cnf

# 不再解釋各個配置項
[mysqld]
server-id=2
log-bin=mysql-bin
binlog-do-db=piumnl
replicate-do-db=piumnl
relay_log=mysql-relay-bin
skip-slave-start=ON
log-slave-updates=ON
symbolic-links=0
# resolve - [Warning] Slave SQL: If a crash happens this configuration does not guarantee that the relay log info will be consistent, Error_code: 0
master-info-repository=table
relay-log-info-repository=table
relay-log-recovery=1
skip-host-cache
skip-name-resolve
sql_mode=NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES

創(chuàng)建備份用戶

masterA & masterB 都要創(chuàng)建備份用戶:

create user 'rep'@'%' identified by 'rep';  # 創(chuàng)建一個賬戶
grant replication slave on *.* to 'rep'@'%'; # 授予該賬戶對任意數(shù)據(jù)庫任意表的主從備份權(quán)限

備注:

  1. Linux 下 MySQL 對 root@% 用戶關(guān)閉了 grant_priv 權(quán)限,所以如果是遠(yuǎn)程登錄會出現(xiàn)授權(quán)失敗的情況
  2. 此處備份用戶帳號和密碼可不一致,此處為了簡化操作使用一樣的帳號和密碼

重啟服務(wù)器

重啟服務(wù)器

開啟備份

masterA

查看 masterB 狀態(tài)

show master status\G;
# 此處需要關(guān)注 File 和 Position 值

開啟備份

stop slave;

# master_log_file 就是第一步操作的 File 值
# master_log_pos 就是第一步操作的 Position 值
change master to master_host=<master_hostname>, master_user=<rep_username>, master_port=<master_port>, master_password=<rep_password>, master_log_file='mysql-log.000003', master_log_pos=154;
start slave;

查看結(jié)果

show slave status\G;
# 查看最重要的兩項,兩個都必須為 Yes ,有一個為 No 都要去查看錯誤日志文件,看看什么地方存在問題
# Slave_IO_Running: Yes
# Slave_SQL_Running: Yes

masterB

反向重復(fù) masterA 的操作

測試

分別在 masterA 和 masterB 中插入數(shù)據(jù),并查看另一臺服務(wù)器是否及時出現(xiàn)預(yù)期的數(shù)據(jù)

問題

MySQL Slave Failed to Open the Relay Log

這應(yīng)該是中繼日志出現(xiàn)問題,可嘗試如下操作

stop slave;
flush logs;
start slave;

Got fatal error 1236 from master when reading data from binary log

從主庫中拉取日志時,發(fā)現(xiàn)主庫的 mysql_bin.index 文件中的第一個文件不存在。

# 進(jìn)行如下操作重置
# 如果二進(jìn)制日志或中繼日志有其他作用,請勿進(jìn)行如下操作
reset master;
reset slave;
flush logs;

<database>.<table>

使用 <database>.<table> 進(jìn)行插入、更新和刪除操作,將不會進(jìn)行備份( 這是巨坑 )?。?!

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持本站。

美國服務(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處理。

實時開通

自選配置、實時開通

免備案

全球線路精選!

全天候客戶服務(wù)

7x24全年不間斷在線

專屬顧問服務(wù)

1對1客戶咨詢顧問

在線
客服

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

客服
熱線

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

關(guān)注
微信

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