免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1388 | 回复: 0
打印 上一主题 下一主题

mysql-ab复制 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-15 23:54 |只看该作者 |倒序浏览
A--:192.168.0.200
B--:192.168.0.201
①  分别在主机A,B上面建立用于Replication的用户.给予REPLICATION SLAVE权限即可
②  shell>mysqld_safe -user=mysql&
A:
shell>mysql -uroot -ppassword
mysql>GRANT REPLICATION SLAVE ON *.*
  -> TO
[email=replicate@'192.168.0.201']replicate@'192.168.0.201'[/email]
identified by '123';
mysql>quit;
停止mysql Server.
B:
shell>mysql -uroot -ppassword
mysql>GRANT REPLICATION SLAVE ON *.*
  -> TO
[email=replicate@'192.168.0.200']replicate@'192.168.0.200'[/email]
identified by '123';
mysql>quit;
停止mysql Server.
③分别修改A,B主机的mysql 配置文件.均如下操作
shell>vi /etc/my.cnf
     ## A主机修改为
[mysqld]
log-bin
server-id=1
     ## B主机修改为
[mysqld]
log-bin
server-id=2
     ##保存退出
④ A 主机用如下方式启动mysql.
shell>mysqld_safe --skip-slave-start --user=mysql&
     ##登陆mysql
shell>mysql -uroot -ppassword
mysql>change master to
  ->MASTER_HOST='192.168.0.201',
  ->MASTER_USER='replicate',
  ->MASTER_PASSWOR='123';
  
mysql> start slave;
⑤ B主机也用如下方式启动mysql.
shell>mysqld_safe --skip-slave-start --user=mysql&
     ##登陆mysql
shell>mydql -uroot -ppassword
mysql>change master to
  ->MASTER_HOST='192.168.0.200',
  ->MASTER_USER='replicate',
  ->MASTER_PASSWORD='123';
mysql> start slave;
⑥现在已基本完成了操作,在任意一台运行如下命令查看master/slave状态
mysql> show master status;  ##如果Server-id没有设置,此处将会有警告信息
+----------------------+--------------+--------------+------------------+
| File         | Position   | Binlog_Do_DB | Binlog_Ignore_DB |
+----------------------+--------------+--------------+------------------+
| localhost-bin.000003 | 98      |       |         |
+----------------------+--------------+--------------+------------------+
1 row in set (0.03 sec)   
****************************************
mysql> show slave status;
+----------------------------------+-------------+-------------+-------------+---------------+----------------------+---------------------+----------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
| Slave_IO_State          | Master_Host | Master_User | Master_Port | Connect_Retry | Master_Log_File   | Read_Master_Log_Pos | Relay_Log_File       | Relay_Log_Pos | Relay_Master_Log_File | Slave_IO_Running | Slave_SQL_Running | Replicate_Do_DB | Replicate_Ignore_DB | Replicate_Do_Table | Replicate_Ignore_Table | Replicate_Wild_Do_Table | Replicate_Wild_Ignore_Table | Last_Errno | Last_Error | Skip_Counter | Exec_Master_Log_Pos | Relay_Log_Space | Until_Condition | Until_Log_File | Until_Log_Pos | Master_SSL_Allowed | Master_SSL_CA_File | Master_SSL_CA_Path | Master_SSL_Cert | Master_SSL_Cipher | Master_SSL_Key | Seconds_Behind_Master |
+----------------------------------+-------------+-------------+-------------+---------------+----------------------+---------------------+----------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
| Waiting for master to send event | 192.168.0.201 | repl    | 3306    | 60      | localhost-bin.000003 | 98         | localhost-relay-bin.000008 | 239      | localhost-bin.000003 | Yes        | Yes        |         |           |          |            |             |               | 0     |      | 0      | 98         | 239       | None      |        | 0       | No         |          |          |         |          |        | 0           |
+----------------------------------+-------------+-------------+-------------+---------------+----------------------+---------------------+----------------------------+---------------+-----------------------+------------------+-------------------+-----------------+---------------------+--------------------+------------------------+-------------------------+-----------------------------+------------+------------+--------------+---------------------+-----------------+-----------------+----------------+---------------+--------------------+--------------------+--------------------+-----------------+-------------------+----------------+-----------------------+
1 row in set (0.01 sec)
*****************************************
mysql> show processlist;
+---+-------------+-------------------+------+-------------+------+-----------------------------------------------------------------------+------------------+
| Id| User    | Host       | db  | Command   | Time | State                                 | Info |
+---+-------------+-------------------+------+-------------+------+-----------------------------------------------------------------------+------------------+
| 1 | system user |          | NULL | Connect   | 2073 | Waiting for master to send event                   | NULL       |
| 2 | system user |          | NULL | Connect   | 1426 | Has read all relay log; waiting for the slave I/O thread to update it | NULL       |
| 5 | repl    | 192.168.0.3:48356 | NULL | Binlog Dump | 832 | Has sent all binlog to slave; waiting for binlog to be updated    | NULL       |
| 6 | root    | localhost     | NULL | Query    | 0  | NULL                                 | show processlist |
+----+-------------+-------------------+------+-------------+------+----------------------------------------------------------------------+------------------+
4 rows in set (0.00 sec)
***此处应该有3个以上的id才正确.
****************************************************************************************************************************************


本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u2/70208/showart_1002385.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP