0

0

Cloning a slave using Mysql Enterprise Backup on a GTID enab_MySQL

php中文网

php中文网

发布时间:2016-06-01 13:16:41

|

1181人浏览过

|

来源于php中文网

原创

mysql 5.6 introduced a new feature called gtid (global transaction identifier) support in replication. for every transaction that is committed on to the server, a gtid of the format :

server_uuid:transaction_idis written into the master's binary log.

This offers the following advantages:

  • Very helpful to set up a slave and create a replication setup.

  • User need not worry about fetching the master's binlog filename and position in the “CHANGE MASTER TO” command which is used to synchronise the slave with the master.

  • Applying GTIDs on slaves ensures consistency – since GTIDs are unique, it cannot be applied more than once on the server.

For a gtid enabled server, the following properties need to be set on both Master and Slave configuration files as shown below in Master.cnf and Slave.cnf

gtid-mode=on

enforce-gtid-consistency=true

log-bin

log-slave-updates=true

Here are the steps to achieve this:

Have a configuration file for master and slave with the below mentioned properties.

So the configuration file for a Master and Slave looks like:

Master.cnf

socket=/tmp/mysql3306.sock

log-slave-updates=true

enforce-gtid-consistency=true

master-info-repository=TABLE

relay-log-info-repository=TABLE

master-verify-checksum=1

datadir=/export/gtid-test/master-data

innodb-file-per-table=on 

Slave.cnf

[mysqld] 

port=3307

socket=/tmp/mysql3307.sock 

binlog-format=MIXED 

log-bin

log-slave-updates=true 

gtid-mode=on 

enforce-gtid-consistency=true 

master-info-repository=TABLE 

relay-log-info-repository=TABLE 

slave-parallel-workers=2

binlog-checksum=CRC32 

slave-sql-verify-checksum=1

server-id=2

binlog-rows-query-log_events=1

datadir=/export/gtid-test/slave-data 

report-host=localhost

Cloning a slave using Mysql Enterprise Backup on a GTID enab_MySQL

On the Master:

Start the server with this configuration file:

./mysqld –defaults-file=/export/gtid-test/master.cnf &

Create a user and grant 'replication' privileges to that user:

mysql> create user 'replication'@'localhost' identified by 'reppwd';

mysql> grant super,replication slave on *.* to 'replication'@'localhost';

Now, you can use Mysql Enterprise Backup(MEB), which will simplify this task of setting up a new slave from an existing server (which will serve as “master” in this replication environment),

On MEB:

1. Use Mysql Enterprise Backup to take a backup of the master.

堆友
堆友

Alibaba Design打造的设计师全成长周期服务平台,旨在成为设计师的好朋友

下载

./mysqlbackup -uroot --socket=/tmp/mysql3306.sock –backup-dir=/export/gtid-test/slave-data-to-rest/ backup

Now the meta folder under the backup directory contains a new file named backup_gtid_executed.sql.

(In this case, /export/gtid-test/slave-data-to-rest/meta/backup_gtid_executed.sql)

Here are the contents of backup_gtid_executed.sql:

# On a new slave, issue the following command if GTIDs are enabled:

SET @@GLOBAL.GTID_PURGED='6efe48e8-b63c-11e3-a730-0021cc6bab7c:1-12';

# Use the following command if you want to use the GTID handshake protocol:

# CHANGE MASTER TO MASTER_AUTO_POSITION=1;

MEB will simplify the task of cloning a slave with the help of this file which contains the sql to set the GTID_PURGED on the slave (this is the GTID_EXECUTED value of the Master)

On the Slave:

2. Now to setup a new slave server, restore the backed up contents using “copy-back-and-apply-log” operation:

./mysqlbackup --defaults-file=/export/gtid-test/slave.cnf --backup-dir=/export/gtid-test/slave-data-to-rest/ copy-back-and-apply-log

slave.cnf contains the “datadir” where the backup contents will be restored. So no need to pass 'datadir' in the command line.

An image backup is much more efficient, as the image can be streamed onto the slave machine and restored directly. You can check outRestore directly on the remote Machine from backup streamfor more information.

The new server is ready. Start the slave server.

./mysqld –defaults-file=/export/gtid-test/slave.cnf &

Observe that the restored directory is the datadirectory (as mentioned in slave.cnf) of the slave server

This can be synchronised with the master by doing the following simple steps:

mysql> show slave status;

This is an empty set as the slave is not synchronised still.

mysql> show global variables like '%gtid_executed%';

+---------------+------------------------------------------+

| Variable_name | Value |

+---------------+------------------------------------------+

| gtid_executed | 16446ee3-bad6-11e3-8530-0021cc6bab7c:1-2 |

+---------------+------------------------------------------+

1 row in set (0.00 sec)

3. Now to synchronise with Master – to set the gtid_purged, the gtid_executed on the slave need to be empty. Reset Master to do this.

mysql> reset master;

mysql> show global variables like '%gtid_executed%';

+---------------+-------+

| Variable_name | Value |

+---------------+-------+

| gtid_executed |     |

+---------------+-------+

4 a. Execute the backup_gtid_executed.sql to set the GTID_PURGED on the slave.

mysql> /. /export/gtid-test/slave-data-to-rest/meta/backup_gtid_executed.sql

4 b. Synchronise slave with Master;

mysql> change master to master_host='', master_port= master_auto_position=1;

Setting master_auto_position=1 will automatically replicate the changes.

5. Start the slave with the username and password to connect to Master.

mysql> start slave USER='replication' PASSWORD='reppwd';

mysql> show slave status /G

Look for:

Retrieved_Gtid_Set: 6efe48e8-b63c-11e3-a730-0021cc6bab7c:13

Executed_Gtid_Set: 6efe48e8-b63c-11e3-a730-0021cc6bab7c:1-13

which shows that the slave has all the transactions from 1-13.

This way, the backup taken with Mysql Enterprise Backup can be used to set any number of slaves for the master in a replication environment.

You can also refer :Using MEB with Replication

本站声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

相关专题

更多
php源码安装教程大全
php源码安装教程大全

本专题整合了php源码安装教程,阅读专题下面的文章了解更多详细内容。

150

2025.12.31

php网站源码教程大全
php网站源码教程大全

本专题整合了php网站源码相关教程,阅读专题下面的文章了解更多详细内容。

88

2025.12.31

视频文件格式
视频文件格式

本专题整合了视频文件格式相关内容,阅读专题下面的文章了解更多详细内容。

90

2025.12.31

不受国内限制的浏览器大全
不受国内限制的浏览器大全

想找真正自由、无限制的上网体验?本合集精选2025年最开放、隐私强、访问无阻的浏览器App,涵盖Tor、Brave、Via、X浏览器、Mullvad等高自由度工具。支持自定义搜索引擎、广告拦截、隐身模式及全球网站无障碍访问,部分更具备防追踪、去谷歌化、双内核切换等高级功能。无论日常浏览、隐私保护还是突破地域限制,总有一款适合你!

61

2025.12.31

出现404解决方法大全
出现404解决方法大全

本专题整合了404错误解决方法大全,阅读专题下面的文章了解更多详细内容。

493

2025.12.31

html5怎么播放视频
html5怎么播放视频

想让网页流畅播放视频?本合集详解HTML5视频播放核心方法!涵盖<video>标签基础用法、多格式兼容(MP4/WebM/OGV)、自定义播放控件、响应式适配及常见浏览器兼容问题解决方案。无需插件,纯前端实现高清视频嵌入,助你快速打造现代化网页视频体验。

16

2025.12.31

关闭win10系统自动更新教程大全
关闭win10系统自动更新教程大全

本专题整合了关闭win10系统自动更新教程大全,阅读专题下面的文章了解更多详细内容。

12

2025.12.31

阻止电脑自动安装软件教程
阻止电脑自动安装软件教程

本专题整合了阻止电脑自动安装软件教程,阅读专题下面的文章了解更多详细教程。

5

2025.12.31

html5怎么使用
html5怎么使用

想快速上手HTML5开发?本合集为你整理最实用的HTML5使用指南!涵盖HTML5基础语法、主流框架(如Bootstrap、Vue、React)集成方法,以及无需安装、直接在线编辑运行的平台推荐(如CodePen、JSFiddle)。无论你是新手还是进阶开发者,都能轻松掌握HTML5网页制作、响应式布局与交互功能开发,零配置开启高效前端编程之旅!

2

2025.12.31

热门下载

更多
网站特效
/
网站源码
/
网站素材
/
前端模板

精品课程

更多
相关推荐
/
热门推荐
/
最新课程
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号