首页 > 数据库技术 > 详细

MySQL一主多从

时间:2018-04-07 20:57:30      阅读:276      评论:0      收藏:0      [点我收藏+]
主192.168.65.128上配置/etc/my.cnf

技术分享图片

[root@localhost ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL.. SUCCESS!


备份数据

从1、192.168.65.129的/etc/my.cnf

技术分享图片

[root@localhost ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!


从2、192.168.65.130的/etc/my.cnf

技术分享图片

[root@localhost ~]# /etc/init.d/mysqld restart
Shutting down MySQL.. SUCCESS!
Starting MySQL. SUCCESS!


主上备份数据

[root@localhost ~]# mysqldump -uroot -p123456 --all-databases > mysqlall.sql


传输数据到从上

[root@localhost ~]# scp mysqlall.sql 192.168.65.129:/tmp/
[root@localhost ~]# scp mysqlall.sql 192.168.65.130:/tmp/


主上创建用作主从同步的虚拟用户

mysql> grant replication slave on *.* to 'repl'@192.168.65.129 identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> grant replication slave on *.* to 'repl'@192.168.65.130 identified by '123456';
Query OK, 0 rows affected (0.00 sec)

mysql> show master status;

技术分享图片


锁表(做实验没有数据变化,可以不锁表)

mysql> flush tables with read lock;
Query OK, 0 rows affected (0.00 sec)


在从上恢复数据

[root@localhost /]# mysql -uroot -p123456 < /tmp/mysqlall.sql
mysql> stop slave;
Query OK, 0 rows affected (0.00 sec)

mysql> change master to master_host = '192.168.65.128', master_user = 'repl', master_port=3306, master_password='123456', master_log_file = 'thermos.000001', master_log_pos=542;
Query OK, 0 rows affected, 2 warnings (0.01 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> show slave status\G

技术分享图片


和从1一样,配置从2

技术分享图片

成功!



如有错误,敬请指出,谢谢!

MySQL一主多从

原文:http://blog.51cto.com/11530642/2095441

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!