Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Setting method of MySQL based on GTID replication

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following brings you about the setting method of MySQL based on GTID replication. I believe you must have read a similar article. What's the difference between what we bring to everyone? Let's take a look at the body. I'm sure you'll get something after reading the GTID replication-based setup method of MySQL.

The concept of GTID

GTID (full name global transaction identifier) is the unique identifier of the transaction. The format is as follows:

GTID = source_id:transaction_id

Source_id: identifies the source cloud server, which is usually the server_uuid of the cloud server

Transaction_id: the sequence number sorted according to the order of transactions committed on the CVM.

For example:

60f9111a-cdba-11e7-b354-005056a30507:1

Add the following information to the configuration file to enable GTID mode

[mysqld]

Gtid_mode=ON

When GTID mode is enabled, you can view the executed GTID collection with the following statement.

Mysql > show master status

The application of GTID in replication is in the main library: when a transaction commits on the main library, the transaction is assigned a GTID,GTID to write to the log before the transaction is written to the binary log of the main library. Get the binary log of the master library from the library and store it in the secondary log of the slave library (relay log). Read GTID from the library and set the value of gtid_next to this GTID. This tells the slave library that the next transaction must use this GTID record. Verify from the library that GTID has been used in its own binary log. If not, GTID is written to the slave library, the transaction is applied, and the transaction is logged to the binary log of the slave library. Since the gtid_next is not empty, the slave library does not generate a new GTID for the transaction, but sets up GTID-based replication using the GTID obtained from the master library

It is not much different from normal replication, except that both the master library and the slave library need to be enabled for gitd_mode and enforce-gitd-consistency. If the slave library is version 5.6, you also need to open-- log-bin and-- log-slave-updates on both the master and slave libraries. (no matter what version, the main library must turn on log-bin)

This is because after MySQL5.7.5, GTIDs is stored in the gtid_ executed table of the mysql system library.

Modify the configuration file and restart the database

Add the following to my.cnf

[mysqld]

Gtid_mode=ON

Enforce-gtid-consistency

Log-bin

Log-slave-updates=1

Create an account for replication on the main database

Create user 'repl'@'hostname'

Grant REPLICATION SLAVE ON *. * TO 'repl'@'hostname'

Synchronize the data of the master and slave libraries (if required)

Use mysqldump or other tools to synchronize data

Set up GTIDs-based replication on the slave library, using the following statement

Mysql > CHANGE MASTER TO

MASTER_HOST = host

MASTER_PORT = port

MASTER_USER = user

MASTER_PASSWORD = password

MASTER_AUTO_POSITION = 1

Check replication status

Mysql > show salve status\ G

Do you think you want to set up MySQL based on GTID replication above? If you want to know more about it, you can continue to follow our industry information section.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report