mysql主主复制

server1:IP=192.168.1.103,port=3306

server2;IP=192.168.1.100,port=3306

step1:分别新建slave账户

grant replication slave on *.* to 'backup'@'%' identified by 'backup'
step2:/etc/mysql/my.cnf配置
server-id               = 1
log_bin                 = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
max_binlog_size         = 100M
#binlog_do_db           = include_database_name
#binlog_ignore_db       = include_database_name
binlog_do_db            =test2
binlog_ignore_db        =mysql
replicate_do_db         =test2
replicate_ignore_db=mysql,information_schema

log_slave_updates
sync_binlog=1
auto_increment_offset=1
auto_increment_increment=2

server-id               = 2
log_bin                 = /var/log/mysql/mysql-bin.log
expire_logs_days        = 10
max_binlog_size         = 100M

binlog_do_db=test2
binlog_ignore_db=mysql
replicate_do_db=test
replicate_ignore_db=mysql,information_schema
log_slave_updates
sync_binlog=1
auto_increment_offset=2
auto_increment_increment=2
slave_skip_errors=all
step3:重启mysql服务
root@ubuntu:~# service mysql restart
mysql start/running, process 2458

root@ubuntu:~# service mysql restart
mysql start/running, process 1626
step4:查看master status
mysql> show master status \G
*************************** 1. row ***************************
            File: mysql-bin.000002
        Position: 106
    Binlog_Do_DB: test2
Binlog_Ignore_DB: mysql
1 row in set (0.00 sec)

mysql> show master status \G
*************************** 1. row ***************************
            File: mysql-bin.000002
        Position: 106
    Binlog_Do_DB: test2
Binlog_Ignore_DB: mysql
1 row in set (0.00 sec)
step5:修改master

mysql> change master to 
    -> master_host ='192.168.1.100',
    -> master_port =3306
    -> ,master_user='backup',
    -> master_password='backup',
    -> master_log_file='mysql-bin.000002',
    -> master_log_pos=106;

mysql> change master to 
    -> master_host='192.168.1.103',
    -> master_port=3306,
    -> master_user='backup',
    -> master_password='backup',
    -> master_log_file='mysql-bin.000002',
    -> master_log_pos=106;
step6:查看slave status
mysql> show slave status \G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.100
                  Master_User: backup
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000002
          Read_Master_Log_Pos: 106
               Relay_Log_File: ubuntu-relay-bin.000002
                Relay_Log_Pos: 251
        Relay_Master_Log_File: mysql-bin.000002
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: test2
          Replicate_Ignore_DB: mysql,information_schema

mysql> show slave status \G
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.103
                  Master_User: backup
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000002
          Read_Master_Log_Pos: 106
               Relay_Log_File: ubuntu-relay-bin.000002
                Relay_Log_Pos: 251
        Relay_Master_Log_File: mysql-bin.000002
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: test
          Replicate_Ignore_DB: mysql,information_schema

step7:测试
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值