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

  1. Check the wrapped SQLException cause in the logs for the precise JDBC error code/message.
  2. Verify connectivity and credentials: mysql -h <host> -P <port> -u <user> -p -e "SELECT @@global.gtid_mode;"
  3. Grant the CDC user permission to read global variables: GRANT SELECT, REPLICATION CLIENT ON *.* TO '<user>'@'%';
  4. Check server health/network stability between SeaTunnel and MySQL (timeouts, proxy idle disconnects, max_connections).
  5. 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

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


AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10). Data as JSON: /api/errors/6687a7def6760b51. Report an issue: GitHub.