本次環(huán)境:虛擬機(jī)下
服務(wù)器:Ubuntu 14.04 LTS
數(shù)據(jù)庫: 5.5.37
端口:3306
主IP:192.168.63.133
從IP:192.168.63.134
授權(quán)賬號:
user:suxh
password:111111
好了交代完環(huán)境:我們直接配置:
第一步:主從兩臺服務(wù)器要有同樣的數(shù)據(jù)庫(需要同步的)這里用的是backup 數(shù)據(jù)庫(不多說了,在同步開始前,把主庫的復(fù)制一份到從庫就行了)
第二步配置主(master)數(shù)據(jù)庫 編輯/etc/my.cnf 主要是開啟二進(jìn)制日志 和設(shè)置要同步的數(shù)據(jù)庫 等一些參數(shù)
1
2
3
4
5
6
7
8
9
|
# binary logging format - mixed recommended binlog_format=mixed binlog-ignore-db=mysql binlog-do-db=backup # required unique id between 1 and 2^32 - 1 # defaults to 1 if master-host is not set # but will not function as a master if omitted server-id = 1 |
參數(shù)解釋下:
server-id 這個是唯一的不能跟從服務(wù)器相同。
binlog_format 二進(jìn)制文件的格式
binlog_ignore-db 忽略的數(shù)據(jù)庫
binlog-do-db 要同步的數(shù)據(jù)庫
設(shè)置完了以后 重啟數(shù)據(jù)庫就可以了。
第三步從數(shù)據(jù)庫:
同樣修改/etc/my.cnf 在mysql 版本5.1.7 不支持master-host”類似的參數(shù); 所以這里只要配置server-id=2 就可以了
然后登陸從數(shù)據(jù)庫設(shè)置
1
2
|
change master to master_host= '192.168.63.133' , master_user= 'suxh' , master_password= '111111' ; slave start; |
基本配置就好了。這是我的簡要筆記。