Build MySQL Replication Environment

The post demonstrates how to build replication environment with 2 new MySQL servers which are running on 64-bit Ubuntu 14.04 LTS machines.

  • Master: {MySQL: 5.7.5, IP Address: 192.168.0.100}
  • Slave  : {MySQL: 5.7.5, IP Address: 192.168.0.101}

 

Configure the Master

Backup MySQL configuration file.

cp /etc/mysql/my.cnf /etc/mysql/my.cnf.backup

Open my.cnf, set server-id and log-bin, and change bind-address.

server-id=1
log-bin=/var/log/mysql/mysql-bin.log
bind-address=192.168.0.100

Restart master MySQL server to apply these settings.

service mysql restart

Create Replication user.

mysql -u root -p --prompt='master>'
master> create user repl_user@192.168.0.101;
master> grant Replication Slave on *.* to repl_user@192.168.0.101 identified by 'password';

Lock the Master, note binary log name and position.

master> flush tables with read lock;
master> show master status; # In this post, the binary log file name is mysql-bin.000001, the position is 439.

Create a data snapshot using mysqldump. (start another session and run the followoing command, and then copy the db.dump to the Slave)

mysqldump -u root -p --all-databases > db.dump

Release the read lock.

master> unlock tables;

 

Configure the Slave

Backup MySQL configuration file.

cp /etc/mysql/my.cnf /etc/mysql/my.cnf.backup

Open my.cnf, set server-id and change bind-address.

server-id=2
bind-address=192.168.0.101

Restart slave MySQL server.

service mysql restart

Set the Master configuration.

mysql -u root -p --prompt='slave>'
slave> change master to master_host='10.110.77.181', master_user='repl_user', master_password='OpsMgr2007R2', master_log_file='mysql-bin.000001', master_log_pos=439;
slave> start slave;

 

Check if replication works

On the Master, create a database and a table and add a row.

master> create database test_replication;
master> use test_replication;
master> create table t1 (Id int not null primary key);
master> insert into t1 values (777);

 

On the Slave, check if the replication works.

slave> show databases;
slave> select * from test_replication.t1;

 

转载于:https://www.cnblogs.com/jeffreyf/p/build-mysql-replication-environment.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MySQL replicationMySQL数据库的一种特性,它允许将数据从一个MySQL服务器复制到另一个MySQL服务器。主要用于实现高可用性、读写分离和数据备份等需求。 MySQL replication基于主从模型,包括一个主服务器和一个或多个从服务器。主服务器负责处理写操作(INSERT、UPDATE、DELETE),而从服务器负责复制主服务器上的数据,并处理读操作(SELECT)。 主服务器将写操作以二进制日志(binary log)的形式记录下来,并将这些日志传递给从服务器。从服务器将这些日志应用到自己的数据库中,以保持与主服务器的数据一致性。 MySQL replication提供了以下几种常见的复制方式: 1. 异步复制(Asynchronous Replication):主服务器将二进制日志发送给从服务器,然后立即返回给客户端,不等待从服务器的响应。这种方式效率较高,但在主服务器故障时可能会丢失一部分数据。 2. 半同步复制(Semi-Synchronous Replication):主服务器将二进制日志发送给至少一个从服务器,并等待至少一个从服务器确认接收到日志后才返回给客户端。这种方式提高了数据的可靠性,但效率稍低。 3. 同步复制(Synchronous Replication):主服务器将二进制日志发送给所有从服务器,并等待所有从服务器确认接收到日志后才返回给客户端。这种方式提供了最高的数据可靠性,但对性能有较大的影响。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值