標籤:mysql
作業系統:Red Hat Enterprise Linux 6.6 x86_64
伺服器資訊:
master.mysql.whh.org 192.168.255.1
slave.mysql.whh.org 192.168.255.2
master伺服器配置:
1- 編輯/etc/my.cnf檔案,設定伺服器server-id為1,id號建議使用伺服器ip地址最後一位。
2- 重啟服務,service mysqld restart。
3- 設定從伺服器登入的使用者名稱和密碼並授權。
grant replication slave,replication client on *.* to [email protected]‘192.168.255.2‘ identified by ‘slave‘;
flush privileges;
\q
slave伺服器配置:
1- 在slave上使用master上建立的使用者名稱和密碼串連mysql資料庫,進行驗證。
mysql -h 192.168.255.1 -u slave -p
2- 驗證成功後退出。
3- 編輯/etc/my.cnf檔案,設定伺服器server-id為2,id號建議使用伺服器ip地址最後一位。
4- 串連本地mysql資料庫,配置slave服務。
reset master;
change master to
master_host=‘192.168.255.1‘,
master_user=‘slave‘,
master_password=‘slave‘,
master_log_file=‘mysql-bin.000001‘,
master_log_pos=0;
slave start;
show slave status\G
\q
slave伺服器資訊:
650) this.width=650;" src="/e/u261/themes/default/images/spacer.gif" style="background:transparent url("/e/u261/lang/zh-cn/images/localimage.png") no-repeat scroll center;border:1px solid rgb(221,221,221);" alt="spacer.gif" />
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
兩個欄位資訊為Yes,表示主從配置成功。
測試:
在master伺服器上建立資料庫,然後在slave伺服器上查詢看是否存在剛建立的資料庫。
說明:
1- 安裝之前的安裝方法,預設開啟了bin日誌,所以master與slave服務的my.cnf設定檔修改server-id即可。
2- 因為伺服器是剛安裝配置完mysql,所以二進位檔案名稱與pos就可以寫成mysql-bin.000001和0。
3- 如果服務跑了一段時間再來類比這個情況,那先備份資料,然後清空資料庫目錄,然後使用mysql_install_db
指令碼初始化資料庫。
本文出自 “whh881114” 部落格,請務必保留此出處http://whh881114.blog.51cto.com/9520067/1605245
02- MySQL主從複製(MySQL剛安裝完成)