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

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

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

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

分享:

  在 Slave 端查看是否能够更新:

  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 6   
  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> show databases;   
  10. +--------------------+   
  11. Database   |   
  12. +--------------------+   
  13. | information_schema |   
  14. | foo|   
  15. | mysql  |   
  16. | test   |   
  17. |abc  |   
  18. +--------------------+   
  19. 5rows in set (0.00 sec)   
  20. mysql> use abc;   
  21. Reading table information for completion of table and column names   
  22. You can turn off this feature to get a quicker startup with -A   
  23. Database changed   
  24. mysql> show tables;   
  25. +---------------+   
  26. | Tables_in_abc |   
  27. +---------------+   
  28. | test1 |   
  29. +---------------+   
  30. 1 row in set (0.03 sec)   
  31.  mysql> select * from test1;   
  32. +--------------+------+------------------+   
  33. | IP   | USER | MAIL |   
  34. +--------------+------+------------------+   
  35. | 192.168.7.66 | test | test@test.com.cn |   
  36. +--------------+------+------------------+   
  37. 1 row in set (0.00 sec)

  从上面的结果可以看到 Master 端的数据可以同步到 Slave 端里面。说明此时主从数据库的同步问题已经成功解决。

  三、补充资料

  关于如何连接到远程 MySQL 问题,可以采取下面的步骤:

  首先先登录到远程机器:

  1. jian.ma@camlit ~: ssh root@192.168.56.103   
  2. password: xxx  
  3. root@test2 ~:

  编辑配置文件:

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. bind-address=192.168.56.103###此 IP 地址为 MySQL 本机的 IP 地址  
  7. [mysqld_safe]   
  8. log-error=/var/log/mysqld.log   
  9. pid-file=/var/run/mysqld/mysqld.pi

  重启服务:

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

  创建测试数据库:

43/4<1234>
价值398元的测试课程免费赠送,填问卷领取吧!

关注51Testing

联系我们

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

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

沪ICP备05003035号

沪公网安备 31010102002173号