Mysql的主从大概分为多个模式,目前搭建的这个是一个主库跟一个备库的模式。
Master配置增加如下:
#server-id:为主服务器A的ID值
#log-bin:二进制变更日值
[mysqld]
#master setting start
server-id = 1
#synchronous
#需要备份的数据库,可以填多个
binlog-do-db=test_backup
binlog-do-db=test_backup1
log_bin = mysql-bin
#master setting end
Slave的配置如下:
[mysqld]
#slave setting start
server-id = 2
#这里的名字跟Master的名字配置一样
log_bin = mysql-bin
relay_log = mysql-relay-bin
log_slave_updates = 1
#备份库的名称
replicate-do-db = test_backup
replicate-do-db = test_backup1
#slave setting end
Slave配置以上之后,进入到Mysql的控制台,然后敲以下命令:
CHANGE MASTER TO MASTER_HOST='your hosts',
MASTER_USER='account_name',
MASTER_PASSWORD='password',
MASTER_LOG_FILE='mysql-bin<span style="widows: auto; font-family: 微软雅黑;">',</span>
MASTER_LOG_POS=0;
把上面的参数进行替换成自己的即可。
mysql> SHOW SLAVE STATUS\G
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: server1
Master_User: repl
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000001
Read_Master_Log_Pos: 4
Relay_Log_File: mysql-relay-bin.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000001
Slave_IO_Running: No
Slave_SQL_Running: No
...omitted...
Seconds_Behind_Master: NULL