- Newest
- Most votes
- Most comments
The issue you're facing is related to the changes in GTID (Global Transaction Identifier) handling between MySQL 5.7 and 8.0. In MySQL 5.7, anonymous transactions (transactions without a GTID) were allowed, but in MySQL 8.0, all transactions must have a GTID.
it's important to note that in MySQL 5.7, GTIDs were not enabled by default. You had to explicitly enable GTIDs in the MySQL configuration file (
my.cnf
) to use them. If GTIDs were not enabled, transactions could be performed without a GTID, but this was not recommended if you intended to use GTIDs for replication purposes.
The error Cannot replicate anonymous transaction when AUTO_POSITION = 1
is because Debezium is trying to read an anonymous transaction from the binlog, but it's not allowed in MySQL 8.0 when using GTID mode (which is the default).
To resolve this issue, you need to purge the binary logs that contain anonymous transactions, and then restart replication from the first GTID transaction after that point. Here are the steps you can follow:
-
Stop the Debezium Kafka Connect process.
-
Connect to your MySQL instance and identify the first binary log file that contains GTID transactions after the anonymous transaction. You can use the following query to find it:
SHOW BINARY LOGS;
This will list all the binary log files. Look for the first file after mysql-bin-changelog.000022
that doesn't contain any anonymous transactions.
- Purge all binary logs up to the log file you identified in the previous step. For example, if the first GTID transaction is in
mysql-bin-changelog.000024
, run the following command:
PURGE BINARY LOGS TO 'mysql-bin-changelog.000024';
- Restart the Debezium Kafka Connect process, and it should now be able to read the binary logs starting from
mysql-bin-changelog.000024
.
To avoid this issue in the future, you can take the following steps:
-
Before upgrading to MySQL 8.0, make sure to purge all binary logs that contain anonymous transactions.
-
After the upgrade, enable the
binlog_row_image=FULL
setting. This will ensure that Debezium can read the complete row images from the binlog, even if there are any anonymous transactions remaining. -
Consider disabling anonymous transactions in your applications by setting
@@SESSION.GTID_MODE = ON
or@@GLOBAL.GTID_MODE = ON
(depending on your requirements).
Hi,
I wasn't able to run this command
PURGE BINARY LOGS TO 'mysql-bin-changelog.000024';
It kept saying Access denied; you need (at least one of) the SUPER or BINLOG_ADMIN privilege(s) for this operation
. I was not able to figure out a way to get the privilege because the secret and privileges are managed by Terraform.
After a lot of testing and resetting, I was able to figure out another way to fix this. At least, it worked for me.
I turned the snapshot mode on the Debezium application to never (snapshot.mode = never
) and restarted the Debezium application and it helped me get through that Anonymous transaction. The binlog mysql-bin-changelog.000024
is somehow deleted. I just need to change the snapshot mode back to when_needed
and restart the application once again.
This approach not only fixes the existing QA MySQL database problem but also prevents issues when we did our PROD Blue/Green MySQL 5.7 --> 8 upgrade. We just set snapshot.mode = never
before the switchover of Blue/Green deployment, then switchover-blue-green-deployment, toggle the snapshot mode back to the original setting (for me it is when_needed
). Although the Blue/Green upgrade MySQL still created some Anonymous transactions in the binlog, the Debezium application was able to process it or skip it (I am not sure what exactly happened in Debezium during the switchover, but nothing was produced in the Kafka topics)
Relevant content
- asked 10 months ago
- asked 10 months ago
- asked a month ago
- asked a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 8 months ago
- AWS OFFICIALUpdated 2 years ago