搜尋
首頁資料庫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:完整的教程將用戶添加到MySQL:完整的教程May 12, 2025 am 12:14 AM

掌握添加MySQL用戶的方法對於數據庫管理員和開發者至關重要,因為它確保數據庫的安全性和訪問控制。 1)使用CREATEUSER命令創建新用戶,2)通過GRANT命令分配權限,3)使用FLUSHPRIVILEGES確保權限生效,4)定期審計和清理用戶賬戶以維護性能和安全。

掌握mySQL字符串數據類型:varchar vs.文本與char掌握mySQL字符串數據類型:varchar vs.文本與charMay 12, 2025 am 12:12 AM

chosecharforfixed-lengthdata,varcharforvariable-lengthdata,andtextforlargetextfield.1)chariseffity forconsistent-lengthdatalikecodes.2)varcharsuitsvariable-lengthdatalikenames,ballancingflexibilitibility andperformance.3)

MySQL:字符串數據類型和索引:最佳實踐MySQL:字符串數據類型和索引:最佳實踐May 12, 2025 am 12:11 AM

在MySQL中處理字符串數據類型和索引的最佳實踐包括:1)選擇合適的字符串類型,如CHAR用於固定長度,VARCHAR用於可變長度,TEXT用於大文本;2)謹慎索引,避免過度索引,針對常用查詢創建索引;3)使用前綴索引和全文索引優化長字符串搜索;4)定期監控和優化索引,保持索引小巧高效。通過這些方法,可以在讀取和寫入性能之間取得平衡,提升數據庫效率。

mysql:如何遠程添加用戶mysql:如何遠程添加用戶May 12, 2025 am 12:10 AM

ToaddauserremotelytoMySQL,followthesesteps:1)ConnecttoMySQLasroot,2)Createanewuserwithremoteaccess,3)Grantnecessaryprivileges,and4)Flushprivileges.BecautiousofsecurityrisksbylimitingprivilegesandaccesstospecificIPs,ensuringstrongpasswords,andmonitori

MySQL字符串數據類型的最終指南:有效的數據存儲MySQL字符串數據類型的最終指南:有效的數據存儲May 12, 2025 am 12:05 AM

tostorestringsefliceflicyInmySql,ChooSetherightDataTypeBasedyOrneOrneEds:1)USEcharforFixed-LengthStstringStringStringSlikeCountryCodes.2)UseVarcharforvariable-lengtthslikenames.3)USETEXTCONTENT.3)

mysql blob vs.文本:為大對象選擇正確的數據類型mysql blob vs.文本:為大對象選擇正確的數據類型May 11, 2025 am 12:13 AM

選擇MySQL的BLOB和TEXT數據類型時,BLOB適合存儲二進制數據,TEXT適合存儲文本數據。 1)BLOB適用於圖片、音頻等二進制數據,2)TEXT適用於文章、評論等文本數據,選擇時需考慮數據性質和性能優化。

MySQL:我應該將root用戶用於產品嗎?MySQL:我應該將root用戶用於產品嗎?May 11, 2025 am 12:11 AM

No,youshouldnotusetherootuserinMySQLforyourproduct.Instead,createspecificuserswithlimitedprivilegestoenhancesecurityandperformance:1)Createanewuserwithastrongpassword,2)Grantonlynecessarypermissionstothisuser,3)Regularlyreviewandupdateuserpermissions

MySQL字符串數據類型說明了:選擇適合您數據的合適類型MySQL字符串數據類型說明了:選擇適合您數據的合適類型May 11, 2025 am 12:10 AM

mySqlStringDatatAtatPessHouldBechoseBasedondatActarActeristicsAndusecases:1)USEcharforFixed lengthStstringStringStringSlikeCountryCodes.2)usevarcharforvariable-lengtthslikeLikenames.3)usebarnionororvarinyorvarinyorvarybinarydatalgebenedaTalgeextocrabextrapon.4)

See all articles

熱AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover

AI Clothes Remover

用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool

Undress AI Tool

免費脫衣圖片

Clothoff.io

Clothoff.io

AI脫衣器

Video Face Swap

Video Face Swap

使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

將Eclipse與SAP NetWeaver應用伺服器整合。

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

EditPlus 中文破解版

EditPlus 中文破解版

體積小,語法高亮,不支援程式碼提示功能

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

這個專案正在遷移到osdn.net/projects/mingw的過程中,你可以繼續在那裡關注我們。 MinGW:GNU編譯器集合(GCC)的本機Windows移植版本,可自由分發的導入函式庫和用於建置本機Windows應用程式的頭檔;包括對MSVC執行時間的擴展,以支援C99功能。 MinGW的所有軟體都可以在64位元Windows平台上運作。

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

強大的PHP整合開發環境