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

MySQL中怎么配置互為主從

162次閱讀
沒有評論

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

這期內容當中丸趣 TV 小編將會給大家帶來有關 MySQL 中怎么配置互為主從,文章內容豐富且以專業的角度為大家分析和敘述,閱讀完這篇文章希望大家可以有所收獲。

1)  A,B 兩臺 mysql 服務器
一、服務器參數,編輯 /etc/my.cnf

[A 服務器]
server-id = 1
binlog-do-db = test
binlog-ignore-db = mysql
replicate-do-db = test
replicate-ignore-db = mysql
master-host  =  192.168.255.195
master-user  =  repl
master-password =  repl
master-port  =  3306
master-connect-retry = 10
sync-binlog = 1
log-bin=mysql-bin

[B 服務器]
server-id = 2
binlog-do-db = test
binlog-ignore-db = mysql
replicate-do-db = test
replicate-ignore-db = mysql
master-host  =  192.168.255.194
master-user  =  repl
master-password =  repl
master-port  =  3306
master-connect-retry = 10
sync-binlog = 1
log-bin=mysql-bin
 
2)  在 A 和 B 上進行數據庫操作
A/B: Slave stop;
A/B: Reset master;
A: grant replication slave on *.* to  identified by repl
B: grant replication slave on *.* to  identified by repl
A/B: show master status;
A: change master to master_host= 192.168.255.194 ,master_user= repl ,master_password= repl ,master_port=3306,master_log_file= mysql-bin.000001 ,master_log_pos=98;(log 根據 master status)
B:
change master to master_host= 192.168.255.195 ,master_user= repl ,master_password= repl ,master_port=3306,master_log_file= mysql-bin.000006 ,master_log_pos=98; (log 根據 master status)
A/B: slave start;
A/B: show slave status\G;(查看同步狀態)
看到如下狀態就表示同步成功
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Seconds_Behind_Master: 0
 
3)  測試數據庫同步,在 A 的 test 庫里增加表,在 B 的 test 庫里刪除表
Use test;
A:Create table username (id int(15));
查看 B 中是否有 username 這個表
B: drop table username
查看 A 中是否已經刪除 usernam 這個表
A/B : show slave status\G;(再次查看同步狀態,如果沒問題就表示成功)
 
4)  互為同步配置實例
1. A B 互為主從同步 test, 不同步 mysql:
兩個數據庫配置中均設置:binlog-do-db=test, binlog-ignore-db=mysql,replicate-do-db=test,replicate-ignore-db=mysql
2. A B 互為主從只同步 test,不同步其他數據庫,新創建的也不會同步
兩個數據庫配置中均設置:binlog-do-db=test,replicate-do-db=test
3. A B 互為主從不同步 mysql, 同步其他數據庫,譬如創建的新數據庫也會同步
兩個數據庫配置中均設置:binlog-ignore-db=mysql,replicate-ignore-db=mysql
4. A B 互為主從同步所有數據庫,包括新建的數據庫
兩個數據庫配置中均不設置上述四項
 
5) 實現自動同步的 shell 腳本
1.  增加 super 和 replication client on 權限
grant super  on *.* to  identified by repl
grant replication client on *.* to  identified by repl
 
2.  自動同步腳本 autosync.sh
#!/bin/bash
while true
do
status=`/usr/bin/ -uroot -e show slave status\G; |grep Slave_SQL_Running|cut -f2 -d : |sed s/ // `
if [$status != Yes]
then
A=`/usr/bin/mysql -urepl -prepl -h292.168.255.194 -e show master status |grep mysql-bin|awk {print $2} `
/usr/bin/mysql -uroot -e slave stop
/usr/bin/mysql -uroot -e change master to master_host= 192.168.255.194 ,master_user= repl ,master_password= repl ,master_port=3306,
master_log_file= mysql-bin.000001 ,master_log_pos=$A
/usr/bin/mysql -uroot -e slave start
fi
sleep 10
done
 
3.  后臺執行
nohup ./autosync.sh /dev/null 2 1

上述就是丸趣 TV 小編為大家分享的 MySQL 中怎么配置互為主從了,如果剛好有類似的疑惑,不妨參照上述分析進行理解。如果想知道更多相關知識,歡迎關注丸趣 TV 行業資訊頻道。

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-08-03發表,共計2483字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 夏河县| 小金县| 武功县| 常山县| 汉寿县| 娱乐| 旬邑县| 金阳县| 罗源县| 克什克腾旗| 乐都县| 抚远县| 西吉县| 建始县| 成安县| 长白| 东光县| 鹰潭市| 博兴县| 景泰县| 墨玉县| 时尚| 越西县| 丘北县| 富顺县| 南漳县| 迁西县| 崇阳县| 甘泉县| 乐安县| 镇雄县| 从化市| 策勒县| 洛扎县| 沂水县| 五台县| 石楼县| 福贡县| 宁武县| 平南县| 吉安县|