标签:
Mysql Replication作为读写分离的廉价解决方案,支持一主多备的方式进行数据存储,采用二进制日志传送,目前存在着广泛应用,网上相关概念也比较多,不再重复介绍。引用一张官方提供的Replication应用场景图片(http://dev.mysql.com/doc/refman/5.1/en/replication-solutions.html)。本文主要记录了基于Linux环境下的Mysql Replication配置步骤。
IP_PORT | OS | Mysql | |
Master | 10.129.221.14:3306 | CentOS 6.5 | 5.1.73 |
Slave | 10.129.221.16:3306 | CentOS 6.5 | 5.1.73 |
Slave | ... |
mysql> use mysql; mysql> update user set host = ‘%‘ where host =‘127.0.0.1‘ and user = ‘root‘; mysql> update user set password = PASSWORD(‘glf_123‘) where user = ‘root‘; mysql> flush privileges;
mysql> create user ‘repl‘@‘%‘ identified by ‘glf_123‘; mysql> grant replication slave on *.* to ‘repl‘@‘%‘ identified by ‘glf_123‘; mysql> flush privileges;
修改后的user表数据如下:
[mysqld] server-id=1 # 唯一ID log-bin=mysql-bin # 指定日志文件 binlog-do-db=TestDB # 需要同步的数据库 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
[root@VM-CentOS /]# service mysqld restar
mysql> SHOW MASTER STATUS;
显示结果如下:
[mysqld] server-id=2 # 唯一ID read_only=1 # 设置Slave库只读 datadir=/var/lib/mysql socket=/var/lib/mysql/mysql.sock user=mysql # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 [mysqld_safe] log-error=/var/log/mysqld.log pid-file=/var/run/mysqld/mysqld.pid
[root@VM-CentOS /]# service mysqld restart
change master to master_host=‘10.129.221.14‘, master_user=‘repl‘, master_password=‘glf_123‘, master_port=3306, master_log_file=‘mysql-bin.000001‘, master_log_pos=0, master_connect_retry=10;
master_log_file表示Master数据库中的log文件名,通过SHOW MASTER STATUS查询;
master_log_pos 表示需要同步的二进制偏移量 ,0表示全部重新同步;
第八步中SHOW MASTER STATUS查询显示的是当前Position;
mysql> start slave;
mysql> SHOW SLAVE STATUS \G; mysql> show processlist \G;
标签:
原文地址:http://www.cnblogs.com/lengfo/p/4212910.html