設置同步服務器
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 = 3306
replicate-ignore-db=MySQL
replicate-do-db=test
重啟MySQL
3、啟動同步
在主服務器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,那代表已經在同步