手把手教你实现MySQL双机数据同步

发表于:2011-7-01 09:53

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:未知    来源:51Testing软件测试网采编

分享:

  2.2.2 Slave 端设置

  和 master 端一样创建一个相同的数据库:abc

  1. Enter password:   
  2. Welcome to the MySQL monitor.  Commands end with ; or \g.   
  3. Your MySQL connection id is 5   
  4. Server version: 5.0.45-log Source distribution   
  5.    
  6. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.   
  7.    
  8. mysql> create database abc;   
  9. Query OK, 1 row affected (0.31 sec)

  修改配置文件:

root@test2 ~: vi /etc/my.cnf

  1. [mysqld]   
  2. datadir=/var/lib/mysql   
  3. socket=/var/lib/mysql/mysql.sock   
  4. user=mysql   
  5. old_passwords=1   
  6.    
  7. ###增加下面内容  
  8. server_id=2   log-bin=mysql-bin   master-host=192.168.7.67   master-user=test1   master-password=test1   master-port=3306   master-connect-retry=10  ###连接次数  replicate-do-db=abc   ###接受的数据库名  replicate-ignore-db=mysql  ###不要接受的数据库  
  9.    
  10. [mysqld_safe]   
  11. log-error=/var/log/mysqld.log   
  12. pid-file=/var/run/mysqld/mysqld.pid

  重启服务:

root@test2~: /etc/init.d/mysqld restart

  备注:

  配置成功 后会在 mysql 目录(/var/lib/mysql/)下生成 master.info 文件,如果要更改 slave 设置,要先将该文件删除才会起作用。

  进入 mysql,输入下面命令:

  1. root@test2~: mysql -u root -p  
  2. Enter password:   
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.   
  4. Your MySQL connection id is 4   
  5. Server version: 5.0.45-log Source distribution   
  6.    
  7. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.   
  8.    
  9. mysql> slave start;   
  10. Query OK, 0 rows affected, 1 warning (0.00 sec)   
  11. ###查看同步情况  
  12. mysql > show slave status;  或 show master status;

  2.3 结果测试

  在 Master 端进行数据库 abc 的一些操作,如下所示:

  1. jian.ma@camlit ~: mysql  -u root -p   
  2. Enter password:   
  3. Welcome to the MySQL monitor.  Commands end with ; or \g.   
  4. Your MySQL connection id is 3   
  5. Server version: 5.0.77-log Source distribution   
  6.    
  7. Type 'help;' or '\h' for help. Type '\c' to clear the buffer.   
  8.    
  9. mysql> use abc;   
  10. Database changed   
  11. mysql> create table test1 (IP VARCHAR(20),USER VARCHAR(100), MAIL   
  12. VARCHAR(100));   
  13. Query OK, 0 rows affected (1.20 sec)   
  14. mysql> insert into test1(IP,USER,MAIL) values('192.168.7.66''test''test@test.com.cn');   
  15. Query OK, 1 row affected (0.06 sec)

42/4<1234>
软件测试热门课程5选2,填问卷免费领取!

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计

法律顾问:上海漕溪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2022
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号