隨筆-153  評論-235  文章-19  trackbacks-0

          環境:

          兩個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
          posted on 2007-03-16 21:37 流浪汗 閱讀(556) 評論(0)  編輯  收藏 所屬分類: MySQL
          主站蜘蛛池模板: 旬阳县| 五常市| 社会| 台江县| 北海市| 新竹市| 铜鼓县| 鄂托克前旗| 隆昌县| 惠东县| 灵川县| 通道| 金平| 黑山县| 平潭县| 溆浦县| 灵川县| 益阳市| 乌兰县| 昆明市| 莒南县| 武义县| 伊吾县| 宣化县| 玛曲县| 祥云县| 涡阳县| 普兰县| 鄢陵县| 玉溪市| 抚顺县| 菏泽市| 沙湾县| 朔州市| 惠东县| 天全县| 都兰县| 宜君县| 基隆市| 平凉市| 玉龙|