MySQL一主多从
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MySQL一主多从相关的知识,希望对你有一定的参考价值。
主192.168.65.128上配置/etc/my.cnf
[[email protected] ~]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL.. SUCCESS!
备份数据
从1、192.168.65.129的/etc/my.cnf
[[email protected] ~]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS!
从2、192.168.65.130的/etc/my.cnf
[[email protected] ~]# /etc/init.d/mysqld restart Shutting down MySQL.. SUCCESS! Starting MySQL. SUCCESS!
主上备份数据
[[email protected] ~]# mysqldump -uroot -p123456 --all-databases > mysqlall.sql
传输数据到从上
[[email protected] ~]# scp mysqlall.sql 192.168.65.129:/tmp/ [[email protected] ~]# 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)
在从上恢复数据
[[email protected] /]# 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一主多从的主要内容,如果未能解决你的问题,请参考以下文章