10分钟搞定单向复制mysql

1、主服务器192.168.1.95

从服务器 192.168.1.96

2、

主服务器my.cnf

server-id=1

log-bin=mysql-bin

从服务器my.cnf

server-id=1

log-bin=mysql-bin

3、

主服务器

配置用户复制权限

GRANT REPLICATION SLAVE ON *.* TO 'cactiuser'@'192.168.1.95' IDENTIFIED BY '123456';

show master status;
+------------------+----------+--------------+------------------+
| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
+------------------+----------+--------------+------------------+
| mysql-bin.000035 |  2422836 | cactidb      | mysql            |
+------------------+----------+--------------+------------------+
1 row in set (0.00 sec)


4、从服务器


mysql> CHANGE MASTER TO
    ->              MASTER_HOST='192.168.1.95',
    ->              MASTER_USER='cactiuser',
    ->              MASTER_PASSWORD='123456',
    ->              MASTER_LOG_FILE='mysql-bin.000035',
    ->              MASTER_LOG_POS=2422836;


slave start;

show slave status\G;

mysql> show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: Waiting for master to send event
                  Master_Host: 192.168.1.95
                  Master_User: cactiuser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000035
          Read_Master_Log_Pos: 2486083
               Relay_Log_File: mysql2-relay-bin.000002
                Relay_Log_Pos: 63500
        Relay_Master_Log_File: mysql-bin.000035
             Slave_IO_Running: Yes
            Slave_SQL_Running: Yes
              Replicate_Do_DB: 
          Replicate_Ignore_DB: 
           Replicate_Do_Table: 
       Replicate_Ignore_Table: 
      Replicate_Wild_Do_Table: 
  Replicate_Wild_Ignore_Table: 
                   Last_Errno: 0
                   Last_Error: 
                 Skip_Counter: 0
          Exec_Master_Log_Pos: 2486083

5.测试

测试语句

create table name(id int(4),name varchar(20));
insert into name(id,name) values(1,peter);

主服务器

mysql> select * from name;
+------+-------+
| id   | name  |
+------+-------+
|    1 | peter |
+------+-------+
1 row in set (0.00 sec)

从服务器

mysql> select * from name;
+------+-------+
| id   | name  |
+------+-------+
|    1 | peter |
+------+-------+

PS,是不是很有趣,很简单;




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值