MySQL Replication

MySQL Replication

环境:

两个mysql 5.1.16
一个在win xp主机(192.168.0.158)上,一个在虚拟机的win xp上

1.主服务器的my.ini配置如下(把my-medium.ini复制为my.ini):
在[mysqld]里增加
binlog-do-db = test
binlog-ignore-db
= mysql

2.进入主mysql增加复制用户:
grant   file , select , replication  slave  on   * . *   to   backup @ ' % '  identified  by   ' 123456 ' ;

3.查看master状态下重启下mysql:
show master status;

结果为:
+------------------+----------+----------------+--------------------+
| File                       | Position   | Binlog_Do_DB | Binlog_Ignore_DB  |
+------------------+----------+----------------+--------------------+
| mysql-bin.000003 |         102 | test                   | mysql                     |
+------------------+----------+----------------+--------------------+
1 row in set (0.02 sec)


4.主服务器建表:
create   table  t_repliction (id  int   not   null  auto_increment  primary   key ,name  varchar ( 255 ) );

并加一些数据:
insert   into  t_repliction (name)  values  ( ' chenlb ' ),( ' Tenny ' );

5.从服务器的my.ini配置如下(同样把my-medium.ini复制为my.ini):
[ mysqld ]

server-id
= 2  
master-host
= 192.168.0.158
master-user
= backup
master-password
= 123456
master-connect-retry
= 60
replicate-do-db
= test

说明:默认server-id=1要改为2-2^32-1的值,注释有说明
log-bin=mysql-bin要保留

6.启动从服务器,并查看状态:
show slave status;


结果:
*************************** 1. row ***************************
             Slave_IO_State: Waiting for master to send event
                Master_Host: 192.168.0.38
                Master_User: backup
                Master_Port: 3306
              Connect_Retry: 60
            Master_Log_File: mysql-bin.000003
        Read_Master_Log_Pos: 533
             Relay_Log_File: CLB_0-relay-bin.000006
              Relay_Log_Pos: 243
      Relay_Master_Log_File: mysql-bin.000003
           Slave_IO_Running: Yes
          Slave_SQL_Running: Yes
            Replicate_Do_DB: test
        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: 533
            Relay_Log_Space: 1087
            Until_Condition: None
             Until_Log_File:
              Until_Log_Pos: 0
         Master_SSL_Allowed: No
         Master_SSL_CA_File:
         Master_SSL_CA_Path:
            Master_SSL_Cert:
          Master_SSL_Cipher:
             Master_SSL_Key:
      Seconds_Behind_Master: 0
1 row in set (0.00 sec)

ERROR:
No query specified


Slave_IO_Running: Yes
Slave_SQL_Running: Yes
说明成功:

再看是否已经复制test.repliction表
mysql> use test
Database changed
mysql> show tables;
+----------------+
| Tables_in_test |
+----------------+
| t_repliction   |
+----------------+
1 row in set (0.00 sec)

再看是否有数据
mysql> select * from t_repliction;
+----+--------+
| id | name   |
+----+--------+
|  1 | chenlb |
|  2 | Tenny  |
+----+--------+
2 rows in set (0.01 sec)

:) 有喔

现在在主服务器里加了一条记录看看有什么结果:

insert   into  t_repliction (name)  values  ( ' ok ' );


再在从服务器看看结果:
mysql> select * from t_repliction;
+----+--------+
| id | name   |
+----+--------+
|  1 | chenlb |
|  2 | Tenny  |
|  3 | ok     |
+----+--------+
3 rows in set (0.00 sec)

恭喜您成功了 :)


参考: http://zhhaju.blog.hexun.com/2524561_d.html

你可能感兴趣的:(MySQL Replication)