程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> mysql 互為備份

mysql 互為備份

編輯:關於MYSQL數據庫
1、設置同步Master修改 my.cnf 文件,在
# Replication Master Server (default)
# binary logging is required for replication
添加如下內容:
log-bin=/var/log/MySQL/updatelog
server-id = 1
binlog-do-db=test
binlog-ignore-db=mysql重啟MySQL,創建一個MySQL帳號為同步專用GRANT REPLICATION SLAVE,RELOAD,SUPER, ON *.* TO [email protected] IDENTIFIED BY 'back' ;
FLUSH PRIVILEGES ;
2、設置同步Slave修改my.cnf文件,添加
server-id = 2
master-host = 192.168.0.1
master-user = back
master-passWord = back
master-port = 3306replicate-ignore-db=MySQL
replicate-do-db=test重啟MySQL3、啟動同步在主服務器A MySQL命令符下:
show master status;
顯示(當然這個是我機器的情況,你的不可能跟我一樣哈,只是個例子):
+------------------+----------+-------------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+-------------------+------------------+
| updatelog.000028 | 313361 | test | MySQL |
+------------------+----------+-------------------+------------------+在從服務器A MySQL命令符下:
slave stop;
CHANGE MASTER TO MASTER_LOG_FILE='updatelog.000028',MASTER_LOG_POS=313361;
slave start;用show slave status\G;看一下從服務器的同步情況
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
如果都是yes,那代表已經在同步往表裡面寫點數據測試一下看是否同步成功,如果不成功,絕對不是你的RP問題,再檢查一下操作步驟!
4、設置雙向同步修改B服務器的my.cnf,添加
log-bin=/var/log/MySQL/updatelog
binlog-do-db=test
binlog-ignore-db=mysql重啟MySQL,創建一個MySQL帳號為同步專用GRANT REPLICATION SLAVE,RELOAD,SUPER, ON *.* TO [email protected] IDENTIFIED BY 'back' ;
FLUSH PRIVILEGES ;修改A服務器的my.cnf,添加
master-host = 192.168.0.2
master-user = back
master-passWord = back
master-port = 3306replicate-ignore-db=MySQL
replicate-do-db=test重啟MySQL在主服務器B MySQL命令符下:
show master status;
+------------------+----------+-------------------+------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+-------------------+------------------+
| updatelog.000028 | 13753 | test | MySQL |
+------------------+----------+-------------------+------------------+在服務器A MySQL命令符下:
slave stop;
CHANGE MASTER TO MASTER_LOG_FILE='updatelog.000028',MASTER_LOG_POS=13753;
slave start;其實也就是A->B單向同步的反向操作!雙向同步,就這麼簡單啦!
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved