One of the MySQL 5.6 features many people are interested in is Global Transactions IDs (GTIDs). This is for a good reason: Reconnecting a slave to a new master has always been a challenge while it is so trivial when GTIDs are enabled. However, using GTIDs is not only about replacing good old binlog file/position with unique identifiers, it is also using a new replication protocol. And if you are not aware of it, it can bite.
Replication protocols: old vs new
The old protocol is pretty straightforward: the slave connects to a given binary log file at a specific offset, and the master sends all the transactions from there.
The new protocol is slightly different: the slave first sends the range of GTIDs it has executed, and then the master sends every missing transaction. It also guarantees that a transaction with a given GTID can only be executed once on a specific slave.
In practice, does it change anything? Well, it may change a lot of things. Imagine the following situation: you want to start replicating from trx 4, but trx 2 is missing on the slave for some reason.
With the old replication protocol, trx 2 will never be executed while with the new replication protocol, itWILLbe executed automatically.
Here are 2 common situations where you can see the new replication protocol in action.
Skipping transactions
It is well known that the good oldSET GLOBAL sql_slave_skip_counter = N
is no longer supported when you want to skip a transaction and GTIDs are enabled. Instead, to skip the transaction withGTID XXX:N
, you have toinject an empty transaction:
mysql> SET gtid_next = 'XXX:N';mysql> BEGIN; COMMIT;mysql> SET gtid_next = 'AUTOMATIC';
mysql>SETgtid_next='XXX:N'; mysql>BEGIN;COMMIT; mysql>SETgtid_next='AUTOMATIC'; |
Why can’t we usesql_slave_skip_counter
? Because of the new replication protocol!
Imagine that we have 3 servers like the picture below:
Let’s assume thatsql_slave_skip_counter
is allowed and has been used on S2 to skip trx 2. What happens if you make S2 a slave of S1?
Both servers will exchange the range of executed GTIDs, and S1 will realize that it has to send trx 2 to S2. Two options then:
- If trx 2 is still in the binary logs of S1, it will be sent to S2, and the transaction is no longer skipped.
- If trx 2 no longer exists in the binary logs of S1, you will get a replication error.
This is clearly not safe, that’s whysql_slave_skip_counter
is not allowed with GTIDs. The only safe option to skip a transaction is to execute a fake transaction instead of the real one.
Errant transactions
If you execute a transaction locally on a slave (called errant transaction in the MySQL documentation), what will happen if you promote this slave to be the new master?
With the old replication protocol, basically nothing (to be accurate, data will be inconsistent between the new master and its slaves, but that can probably be fixed later).
With the new protocol, the errant transaction will be identified as missing everywhere and will be automatically executed on failover, which has the potential to break replication.
Let’s say you have a master (M), and 2 slaves (S1 and S2). Here are 2 simple scenarios where reconnecting slaves to the new master will fail (with different replication errors):
# Scenario 1
# S1mysql> CREATE DATABASE mydb;# Mmysql> CREATE DATABASE IF NOT EXISTS mydb;# Thanks to 'IF NOT EXITS', replication doesn't break on S1. Now move S2 to S1:# S2mysql> STOP SLAVE; CHANGE MASTER TO MASTER_HOST='S1'; START SLAVE;# This creates a conflict with existing data!mysql> SHOW SLAVE STATUS/G[...]Last_SQL_Errno: 1007 Last_SQL_Error: Error 'Can't create database 'mydb'; database exists' on query. Default database: 'mydb'. Query: 'CREATE DATABASE mydb'[...]
# S1 mysql>CREATEDATABASEmydb; # Mmysql>CREATEDATABASEIFNOTEXISTSmydb; # Thanks to 'IF NOT EXITS', replication doesn't break on S1. Now move S2 to S1: # S2mysql>STOPSLAVE;CHANGEMASTERTOMASTER_HOST='S1';STARTSLAVE; # This creates a conflict with existing data! mysql>SHOWSLAVESTATUS/G [...]Last_SQL_Errno:1007 Last_SQL_Error:Error'Can'tcreatedatabase'mydb';databaseexists' on query. Default database: 'mydb'. Query: 'CREATEDATABASEmydb' [...] |
# Scenario 2
# S1mysql> CREATE DATABASE mydb;# Now, we'll remove this transaction from the binary logs# S1mysql> FLUSH LOGS;mysql> PURGE BINARY LOGS TO 'mysql-bin.000008';# Mmysql> CREATE DATABASE IF NOT EXISTS mydb;# S2mysql> STOP SLAVE; CHANGE MASTER TO MASTER_HOST='S1'; START SLAVE;# The missing transaction is no longer available in the master's binary logs!mysql> SHOW SLAVE STATUS/G[...]Last_IO_Errno: 1236Last_IO_Error: Got fatal error 1236 from master when reading data from binary log: 'The slave is connecting using CHANGE MASTER TO MASTER_AUTO_POSITION = 1, but the master has purged binary logs containing GTIDs that the slave requires.'[...]
# S1 mysql>CREATEDATABASEmydb; # Now, we'll remove this transaction from the binary logs # S1mysql>FLUSHLOGS; mysql>PURGEBINARYLOGSTO'mysql-bin.000008'; # Mmysql>CREATEDATABASEIFNOTEXISTSmydb; # S2mysql>STOPSLAVE;CHANGEMASTERTOMASTER_HOST='S1';STARTSLAVE; # The missing transaction is no longer available in the master's binary logs! mysql>SHOWSLAVESTATUS/G [...]Last_IO_Errno:1236 Last_IO_Error:Gotfatalerror1236frommasterwhenreadingdatafrombinarylog:'The slave is connecting using CHANGE MASTER TO MASTER_AUTO_POSITION = 1, but the master has purged binary logs containing GTIDs that the slave requires.' [...] |
As you can understand, errant transactions should be avoided with GTID-based replication. If you need to run a local transaction, your best option is to disable binary logging for that specific statement:
mysql> SET SQL_LOG_BIN = 0;mysql> # Run local transaction
mysql>SETSQL_LOG_BIN=0; mysql># Run local transaction |
Conclusion
GTIDs are a great step forward in the way we are able to reconnect replicas to other servers. But they also come with new operational challenges. If you plan to use GTIDs, make sure you correctly understand the new replication protocol, otherwise you may end up breaking replication in new and unexpected ways.
I’ll do more exploration about errant transactions in a future post.

Die Position von MySQL in Datenbanken und Programmierung ist sehr wichtig. Es handelt sich um ein Open -Source -Verwaltungssystem für relationale Datenbankverwaltung, das in verschiedenen Anwendungsszenarien häufig verwendet wird. 1) MySQL bietet effiziente Datenspeicher-, Organisations- und Abruffunktionen und unterstützt Systeme für Web-, Mobil- und Unternehmensebene. 2) Es verwendet eine Client-Server-Architektur, unterstützt mehrere Speichermotoren und Indexoptimierung. 3) Zu den grundlegenden Verwendungen gehören das Erstellen von Tabellen und das Einfügen von Daten, und erweiterte Verwendungen beinhalten Multi-Table-Verknüpfungen und komplexe Abfragen. 4) Häufig gestellte Fragen wie SQL -Syntaxfehler und Leistungsprobleme können durch den Befehl erklären und langsam abfragen. 5) Die Leistungsoptimierungsmethoden umfassen die rationale Verwendung von Indizes, eine optimierte Abfrage und die Verwendung von Caches. Zu den Best Practices gehört die Verwendung von Transaktionen und vorbereiteten Staten

MySQL ist für kleine und große Unternehmen geeignet. 1) Kleinunternehmen können MySQL für das grundlegende Datenmanagement verwenden, z. B. das Speichern von Kundeninformationen. 2) Große Unternehmen können MySQL verwenden, um massive Daten und komplexe Geschäftslogik zu verarbeiten, um die Abfrageleistung und die Transaktionsverarbeitung zu optimieren.

InnoDB verhindert effektiv das Phantom-Lesen durch den Mechanismus für den nächsten Kleien. 1) Nächstschlüsselmesser kombiniert Zeilensperr- und Gap-Sperre, um Datensätze und deren Lücken zu sperren, um zu verhindern, dass neue Datensätze eingefügt werden. 2) In praktischen Anwendungen kann durch Optimierung der Abfragen und Anpassung der Isolationsstufen die Verringerungswettbewerb reduziert und die Gleichzeitleistung verbessert werden.

MySQL ist keine Programmiersprache, aber seine Abfragesprache SQL hat die Eigenschaften einer Programmiersprache: 1. SQL unterstützt bedingte Beurteilung, Schleifen und variable Operationen; 2. Durch gespeicherte Prozeduren, Auslöser und Funktionen können Benutzer komplexe logische Operationen in der Datenbank ausführen.

MySQL ist ein Open Source Relational Database Management -System, das hauptsächlich zum schnellen und zuverlässigen Speicher und Abrufen von Daten verwendet wird. Sein Arbeitsprinzip umfasst Kundenanfragen, Abfragebedingungen, Ausführung von Abfragen und Rückgabergebnissen. Beispiele für die Nutzung sind das Erstellen von Tabellen, das Einsetzen und Abfragen von Daten sowie erweiterte Funktionen wie Join -Operationen. Häufige Fehler umfassen SQL -Syntax, Datentypen und Berechtigungen sowie Optimierungsvorschläge umfassen die Verwendung von Indizes, optimierte Abfragen und die Partitionierung von Tabellen.

MySQL ist ein Open Source Relational Database Management -System, das für Datenspeicher, Verwaltung, Abfrage und Sicherheit geeignet ist. 1. Es unterstützt eine Vielzahl von Betriebssystemen und wird in Webanwendungen und anderen Feldern häufig verwendet. 2. Durch die Client-Server-Architektur und verschiedene Speichermotoren verarbeitet MySQL Daten effizient. 3. Die grundlegende Verwendung umfasst das Erstellen von Datenbanken und Tabellen, das Einfügen, Abfragen und Aktualisieren von Daten. 4. Fortgeschrittene Verwendung beinhaltet komplexe Abfragen und gespeicherte Verfahren. 5. Häufige Fehler können durch die Erklärungserklärung debuggen. 6. Die Leistungsoptimierung umfasst die rationale Verwendung von Indizes und optimierte Abfrageanweisungen.

MySQL wird für seine Leistung, Zuverlässigkeit, Benutzerfreundlichkeit und Unterstützung der Gemeinschaft ausgewählt. 1.MYSQL bietet effiziente Datenspeicher- und Abruffunktionen, die mehrere Datentypen und erweiterte Abfragevorgänge unterstützen. 2. Übernehmen Sie die Architektur der Client-Server und mehrere Speichermotoren, um die Transaktion und die Abfrageoptimierung zu unterstützen. 3. Einfach zu bedienend unterstützt eine Vielzahl von Betriebssystemen und Programmiersprachen. V.

Zu den Verriegelungsmechanismen von InnoDB gehören gemeinsame Schlösser, exklusive Schlösser, Absichtsschlösser, Aufzeichnungsschlösser, Lückensperrungen und nächste Schlüsselschlösser. 1. Shared Lock ermöglicht es Transaktionen, Daten zu lesen, ohne dass andere Transaktionen lesen. 2. Exklusives Schloss verhindert, dass andere Transaktionen Daten lesen und ändern. 3.. Intention Lock optimiert die Sperreffizienz. 4. Rekord -Sperr -Indexdatensatz. 5. Gap Lock Locks Index -Aufzeichnungslücke. 6. Die nächste Schlüsselsperrung ist eine Kombination aus Datensatzsperr- und Lückensperrung, um die Datenkonsistenz zu gewährleisten.


Heiße KI -Werkzeuge

Undresser.AI Undress
KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover
Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool
Ausziehbilder kostenlos

Clothoff.io
KI-Kleiderentferner

AI Hentai Generator
Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

Heiße Werkzeuge

mPDF
mPDF ist eine PHP-Bibliothek, die PDF-Dateien aus UTF-8-codiertem HTML generieren kann. Der ursprüngliche Autor, Ian Back, hat mPDF geschrieben, um PDF-Dateien „on the fly“ von seiner Website auszugeben und verschiedene Sprachen zu verarbeiten. Es ist langsamer und erzeugt bei der Verwendung von Unicode-Schriftarten größere Dateien als Originalskripte wie HTML2FPDF, unterstützt aber CSS-Stile usw. und verfügt über viele Verbesserungen. Unterstützt fast alle Sprachen, einschließlich RTL (Arabisch und Hebräisch) und CJK (Chinesisch, Japanisch und Koreanisch). Unterstützt verschachtelte Elemente auf Blockebene (wie P, DIV),

SecLists
SecLists ist der ultimative Begleiter für Sicherheitstester. Dabei handelt es sich um eine Sammlung verschiedener Arten von Listen, die häufig bei Sicherheitsbewertungen verwendet werden, an einem Ort. SecLists trägt dazu bei, Sicherheitstests effizienter und produktiver zu gestalten, indem es bequem alle Listen bereitstellt, die ein Sicherheitstester benötigen könnte. Zu den Listentypen gehören Benutzernamen, Passwörter, URLs, Fuzzing-Payloads, Muster für vertrauliche Daten, Web-Shells und mehr. Der Tester kann dieses Repository einfach auf einen neuen Testcomputer übertragen und hat dann Zugriff auf alle Arten von Listen, die er benötigt.

EditPlus chinesische Crack-Version
Geringe Größe, Syntaxhervorhebung, unterstützt keine Code-Eingabeaufforderungsfunktion

SublimeText3 Linux neue Version
SublimeText3 Linux neueste Version

Dreamweaver Mac
Visuelle Webentwicklungstools