apache/seatunnel · error · ConnectException
Unexpected error while connecting to MySQL and looking at GT
Error message
Unexpected error while connecting to MySQL and looking at GTID mode:
What it means
MySqlJdbcContext.isGtidModeEnabled() queries SELECT @@global.gtid_mode to detect whether GTID replication is on. Any SQLException during that query is wrapped in a ConnectException 'Unexpected error while connecting to MySQL and looking at GTID mode:'. It means the connector's JDBC connection failed while probing server GTID configuration.
Source
Thrown at seatunnel-connectors-v2/connector-cdc/connector-cdc-mysql/src/main/java/io/debezium/connector/mysql/legacy/MySqlJdbcContext.java:262
/**
* Determine whether the MySQL server has GTIDs enabled.
*
* @return {@code false} if the server's {@code gtid_mode} is set and is {@code OFF}, or {@code
* true} otherwise
*/
public boolean isGtidModeEnabled() {
AtomicReference<String> mode = new AtomicReference<String>("off");
try {
jdbc().query(
"SHOW GLOBAL VARIABLES LIKE 'GTID_MODE'",
rs -> {
if (rs.next()) {
mode.set(rs.getString(2));
}
});
} catch (SQLException e) {
throw new ConnectException(
"Unexpected error while connecting to MySQL and looking at GTID mode: ", e);
}
return !"OFF".equalsIgnoreCase(mode.get());
}
/**
* Determine the executed GTID set for MySQL.
*
* @return the string representation of MySQL's GTID sets; never null but an empty string if the
* server does not use GTIDs
*/
public String knownGtidSet() {
AtomicReference<String> gtidSetStr = new AtomicReference<String>();
try {
jdbc.query(
showMasterStmt,
rs -> {View on GitHub (pinned to cf67b549a7)
Solutions
- Check the wrapped SQLException cause in the logs for the precise JDBC error code/message.
- Verify connectivity and credentials: mysql -h <host> -P <port> -u <user> -p -e "SELECT @@global.gtid_mode;"
- Grant the CDC user permission to read global variables: GRANT SELECT, REPLICATION CLIENT ON *.* TO '<user>'@'%';
- Check server health/network stability between SeaTunnel and MySQL (timeouts, proxy idle disconnects, max_connections).
- If using MariaDB or an unsupported variant, confirm the connector supports it and that gtid_mode semantics apply.
Defensive patterns
Strategy: retry
Validate before calling
// Probe GTID visibility with the same credentials before starting the job
try (Connection c = DriverManager.getConnection(jdbcUrl, user, pass);
Statement s = c.createStatement();
ResultSet rs = s.executeQuery("SELECT @@global.gtid_mode")) {
rs.next();
System.out.println("gtid_mode=" + rs.getString(1));
} // failure here predicts the ConnectException; fix privileges/network first Try / catch
try {
startCdcSource(config);
} catch (ConnectException e) {
if (e.getMessage() != null && e.getMessage().contains("GTID mode")) {
log.warn("GTID probe failed, will retry after connectivity check", e.getCause());
// transient SQLExceptions (network blip, failover) may be retried with backoff
retryWithBackoff(() -> startCdcSource(config), 3);
} else {
throw e;
}
} Prevention
- Verify the CDC user can run SELECT @@global.gtid_mode before deploying.
- Keep connections alive across network flakiness: tune connect/read timeouts and proxy idle limits.
- Monitor MySQL availability (restarts, failovers) that can drop the JDBC session mid-probe.
- For MariaDB, confirm connector compatibility and GTID variable semantics.
- Grant REPLICATION CLIENT so the account can read global replication variables.
When it happens
Trigger: Executing the gtid_mode query over the JDBC connection throws SQLException — connection dropped, statement failed, or the query could not be executed on the server.
Common situations: MySQL connection dropped (timeout, server restart, network flake) right after connect; user lacking privileges to read global variables; connecting through a proxy/LB that breaks the session; MySQL variant that doesn't expose gtid_mode (e.g. MariaDB differences).
Understand the failure class
Background: Database query failed: Internal Server Error 500s wrapping SQL, Prisma, and connection failures — what to check first — this error's family across 16 libraries.
Related errors
- Unexpected error while connecting to MySQL and looking at gt
- Unexpected error while connecting to MySQL and looking at GT
- Unexpected error while connecting to MySQL and looking at pr
- Error reading MySQL variables: ${e.getMessage()}
- Failed to split chunks for table " + tableId
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/6687a7def6760b51.
Report an issue: GitHub.