


Detailed explanation of the sample code for changing traditional replication to GTID replication in MySQL 5.7 non-stop business
The following editor will bring you an example of MySQL5.7 changing traditional replication to GTID replication for non-stop business. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let’s follow the editor and take a look.
Due to the advantages of GTID, we need to change the traditional file-pos-based replication to GTID-based replication. How to change online has become a point of concern to us. The details are as follows Method:
Currently we have an M-S structure under traditional replication:
port 3301 master
port 3302 slave
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
|
The following are the specific steps for online changes:
Prerequisite :
1. Requires all mysql versions 5.7.6 or higher.
2. The gtid_mode value of all mysql in the current topology is off.
3. The following operation steps are all in order, do not jump ahead.
Add global System variablesGTID_MODE variable value description:
OFF The new transaction is non-GTID, Slave Only transactions without GTID are accepted. Transactions sent with GTID will report an error.
OFF_PERMISSIVE The new transaction is non-GTID. Slave accepts both transactions without GTID and transactions with GTID.
ON_PERMISSIVE New transaction is GTID, Slave accepts both transactions without GTID and transactions with GTID
ON The new transaction is GTID, Slave only accepts transactions with GTID
Need to pay attention What's interesting is that the changes in these values are in order, that is,
off<--->OFF_PERMISSIVE<--->ON_PERMISSIVE<---> ;ON
cannot jump to execution and will report an error.
#step1:On each mysql instance, set ENFORCE_GTID_CONSISTENCY to warning. Which one is executed first does not affect the result.
1 2 3 4 |
|
Note: After executing this statement, if there is a GTID incompatible statement usage, the relevant information will be recorded in the error log, then the program needs to be adjusted to avoid incompatible writing, Until no incompatible statements are generated, You can check all SQLs through the program, or you can observe the error log for a period of time after setting. This step is very important.
step2: On each mysql instance, set ENFORCE_GTID_CONSISTENCY to ON. Which one is executed first does not affect the result.
Complete in the first step After that, you can set the value to on.
1 2 3 4 5 |
|
step3:On each mysql instance, set GTID_MODE to off_permissiv; which one is executed first does not affect the result
1 2 3 4 5 |
|
step4:In On each mysql instance, set GTID_MODE to on_permissiv;; which one is executed first does not affect the result
1 2 3 4 |
|
step5:Check the variable ONGOING_ANONYMOUS_TRANSACTION on each mysql instance _COUNT
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
You need to wait until this variable is 0
step6: Ensure that all anonymous transactions (non-GTID transactions) have been completely replicated to all servers.
Checking method:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
Check that the value of these two Relay_Master_Log_File is greater than binlog57.000005,
or equal to Relay_Master_Log_File is equal to binlog57.000005 and the value of Exec_Master_Log_Pos is greater than or equal to 154
Or the slave directly uses the function:
1 2 3 4 5 6 7 |
|
If the return result is greater than or equal to 0, it means that all anonymous transactions have been copied
step7: Confirm that there are no anonymous transactions in the entire topology. For example, all previously generated anonymous transactions have been completed. Even if there are no anonymous transactions in the binary log, you can pass flush logs and let mysql to automatically clean up old binary log files.
#step8: On each mysql instance, set GTID_MODE to on,
1 2 3 4 5 |
|
#step9: On each mysql instance In the configuration file my.cnf, add gtid-mode=ON
Verification:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
|
This completes the online conversion from traditional replication to GTID replication.
The above is the detailed content of Detailed explanation of the sample code for changing traditional replication to GTID replication in MySQL 5.7 non-stop business. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values and pointers to data rows, and is suitable for non-primary key column queries.

Article discusses popular MySQL GUI tools like MySQL Workbench and phpMyAdmin, comparing their features and suitability for beginners and advanced users.[159 characters]

Article discusses strategies for handling large datasets in MySQL, including partitioning, sharding, indexing, and query optimization.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.
