検索
ホームページデータベースmysql チュートリアルCloning a slave using Mysql Enterprise Backup on a GTID enab_MySQL

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.

./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 までご連絡ください。
MySQL:BLOBおよびその他のNO-SQLストレージ、違いは何ですか?MySQL:BLOBおよびその他のNO-SQLストレージ、違いは何ですか?May 13, 2025 am 12:14 AM

mysql'sblobissuitable forstoringbinarydatawithinarationaldatabase、whileenosqloptionslikemongodb、redis、andcassandraofferferulesions forunstructureddata.blobissimplerbutcanslowdowdowd withwithdata

MySQLユーザーの追加:構文、オプション、セキュリティのベストプラクティスMySQLユーザーの追加:構文、オプション、セキュリティのベストプラクティスMay 13, 2025 am 12:12 AM

toaddauserinmysql、使用:createuser'username '@' host'identifidedby'password '; here'showtodoitsely:1)chosehostcarefilytoconを選択しますTrolaccess.2)setResourcelimitslikemax_queries_per_hour.3)usestrong、uniquasswords.4)endforcessl/tlsconnectionswith

MySQL:文字列データ型の一般的な間違いを回避する方法MySQL:文字列データ型の一般的な間違いを回避する方法May 13, 2025 am 12:09 AM

toavoidcommonMonmistakeswithStringDatatypesinmysql、undultingStringTypenuste、choosetherightType、andManageEncodingandCollat​​ionsEttingtingive.1)U​​secharforfixed-LengthStrings、Varcharforaible Length、AndText/Blobforlardata.2)setCurrectCherts

MySQL:文字列データ型と列挙?MySQL:文字列データ型と列挙?May 13, 2025 am 12:05 AM

mysqloffersechar、varchar、Text、anddenumforstringdata.usecharforfixed-lengthstrings、varcharerforvariable-length、text forlarger text、andenumforenforcingdataantegritywithaetofvalues。

MySQL BLOB:BLOBSリクエストを最適化する方法MySQL BLOB:BLOBSリクエストを最適化する方法May 13, 2025 am 12:03 AM

MySQLBlob要求の最適化は、次の戦略を通じて実行できます。1。ブロブクエリの頻度を減らす、独立した要求の使用、または読み込みの遅延。 2。適切なブロブタイプ(TinyBlobなど)を選択します。 3。ブロブデータを別々のテーブルに分離します。 4.アプリケーションレイヤーでBLOBデータを圧縮します。 5.ブロブメタデータをインデックスします。これらの方法は、実際のアプリケーションでの監視、キャッシュ、データシェルディングを組み合わせることにより、パフォーマンスを効果的に改善できます。

MySQLにユーザーを追加:完全なチュートリアルMySQLにユーザーを追加:完全なチュートリアルMay 12, 2025 am 12:14 AM

MySQLユーザーを追加する方法を習得することは、データベース管理者と開発者にとって重要です。これは、データベースのセキュリティとアクセス制御を保証するためです。 1)CreateUserコマンドを使用して新しいユーザーを作成し、2)付与コマンドを介してアクセス許可を割り当て、3)FlushPrivilegesを使用してアクセス許可を有効にすることを確認します。

MySQL文字列データ型のマスター:Varchar vs. Text vs. CharMySQL文字列データ型のマスター:Varchar vs. Text vs. CharMay 12, 2025 am 12:12 AM

choosecharforfixed-lengthdata、varcharforvariable-lengthdata、andtextforlargetextfields.1)chariseffienceforconsistent-lengthdatalikecodes.2)varcharsuitsvariaible-lengthdatalikenames、balancingflexibilityandperformance.3)Textisidealforforforforforforforforforforforidex

MySQL:文字列データ型とインデックス:ベストプラクティスMySQL:文字列データ型とインデックス:ベストプラクティスMay 12, 2025 am 12:11 AM

MySQLの文字列データ型とインデックスを処理するためのベストプラクティスには、次のものが含まれます。1)固定長のchar、可変長さのvarchar、大規模なテキストのテキストなどの適切な文字列タイプを選択します。 2)インデックス作成に慎重になり、インデックスを避け、一般的なクエリのインデックスを作成します。 3)プレフィックスインデックスとフルテキストインデックスを使用して、長い文字列検索を最適化します。 4)インデックスを定期的に監視および最適化して、インデックスを小さく効率的に保つ。これらの方法により、読み取りと書き込みのパフォーマンスをバランスさせ、データベースの効率を改善できます。

See all articles

ホットAIツール

Undresser.AI Undress

Undresser.AI Undress

リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover

AI Clothes Remover

写真から衣服を削除するオンライン AI ツール。

Undress AI Tool

Undress AI Tool

脱衣画像を無料で

Clothoff.io

Clothoff.io

AI衣類リムーバー

Video Face Swap

Video Face Swap

完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

ホットツール

VSCode Windows 64 ビットのダウンロード

VSCode Windows 64 ビットのダウンロード

Microsoft によって発売された無料で強力な IDE エディター

WebStorm Mac版

WebStorm Mac版

便利なJavaScript開発ツール

mPDF

mPDF

mPDF は、UTF-8 でエンコードされた HTML から PDF ファイルを生成できる PHP ライブラリです。オリジナルの作者である Ian Back は、Web サイトから「オンザフライ」で PDF ファイルを出力し、さまざまな言語を処理するために mPDF を作成しました。 HTML2FPDF などのオリジナルのスクリプトよりも遅く、Unicode フォントを使用すると生成されるファイルが大きくなりますが、CSS スタイルなどをサポートし、多くの機能強化が施されています。 RTL (アラビア語とヘブライ語) や CJK (中国語、日本語、韓国語) を含むほぼすべての言語をサポートします。ネストされたブロックレベル要素 (P、DIV など) をサポートします。

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

メモ帳++7.3.1

メモ帳++7.3.1

使いやすく無料のコードエディター