1)*.登入mysql資料庫主伺服器,並給從伺服器設定授權使用者.
#mysql-uroot -p123456 test
mysql>grantall (slave) on *.* to user1_zc@192.168.10.2identified by “456”;
or
mysql>grantreplication (slave) on *.* user1_zc@192.168.10.2identified by “pass”;
mysql>showgrants for user1_zc@192.168.10.2;//檢查使用者是否授權成功
ormysql>selectuser,host,password from mysql.user;
2)*.登入mysql資料庫主伺服器清空bin-log日誌記錄.
mysql>resetmaster;
mysql>showmaster status;
3)*.修改mysql資料庫主伺服器的設定檔/etc/my.cnf,開戶bin-log,並設定server-id的值並重啟服務.
#vi/etc/my.cnf 預設開啟了)
log-bin=mysql-bin
server-id=1(server-id只要設定一次就可以)
#servicemysqld restart or /usr/local/mysql/bin/mysqld_safe –user=mysql &
4)*.備份mysql資料庫主伺服器資料庫)
#/usr/local/mysql/bin/mysqldump -uroot -p123456 test -l -F > /tmp/test.sql
5)*.把備份的資料庫)恢複到從伺服器上
#scp/tmp/test.sql root@192.168.10.2:/tmp/
6)*.再從mysql資料庫伺服器上恢複資料(庫)
#/usr/local/mysql/bin/mysql -uroot -p123456 test < /tmp/test.sql
mysql>showtables;
mysql>select * from t1;//觀察主從資料是否一至
7)*.清空從伺服器上的bin-log日誌(保證主從資料庫原始bin-log日誌一致)
mysql>resetmaster;
mysql>showmaster status;
8).*修改從資料庫伺服器的設定檔my.cnf,並重啟服務.
log-bin=mysql-bin
server-id=2(server-id只要設定一次就可以)
master-host =192.168.10.1
master-user =user1_zc
master-password = 456
master-port = 3306
#servicemysqld restart or /usr/local/mysql/bin/mysqld_safe –user=mysql &
9).從測試user1_zc使用者能否從從伺服器登入主伺服器
#/usr/local/mysql/bin/mysql-uuser1_zc -p456 -h192.168.10.2 test
10).測試在主伺服器上插入資料,在從伺服器上檢查資料是否一致。
本文出自 “mhf_zzjc” 部落格,請務必保留此出處http://1meir3a.blog.51cto.com/6176787/1298417