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_purged variable: 

What it means

MySqlJdbcContext.purgedGtidSet() reads the `gtid_purged` system variable from MySQL to learn which GTIDs have already been purged from the binlogs. An SQLException while querying this variable is wrapped in a ConnectException with this message, preventing the connector from determining a safe restart GTID position.

Source

Thrown at seatunnel-connectors-v2/connector-cdc/connector-cdc-mysql/src/main/java/io/debezium/connector/mysql/legacy/MySqlJdbcContext.java:341

     * Get the purged GTID values from MySQL (gtid_purged value)
     *
     * @return A GTID set; may be empty if not using GTIDs or none have been purged yet
     */
    public GtidSet purgedGtidSet() {
        AtomicReference<String> gtidSetStr = new AtomicReference<String>();
        try {
            jdbc.query(
                    "SELECT @@global.gtid_purged",
                    rs -> {
                        if (rs.next() && rs.getMetaData().getColumnCount() > 0) {
                            gtidSetStr.set(
                                    rs.getString(
                                            1)); // GTID set, may be null, blank, or contain a GTID
                            // set
                        }
                    });
        } catch (SQLException e) {
            throw new ConnectException(
                    "Unexpected error while connecting to MySQL and looking at gtid_purged variable: ",
                    e);
        }

        String result = gtidSetStr.get();
        if (result == null) {
            result = "";
        }

        return new GtidSet(result);
    }

    /**
     * Determine if the current user has the named privilege. Note that if the user has the "ALL"
     * privilege this method returns {@code true}.
     *
     * @param grantName the name of the MySQL privilege; may not be null
     * @return {@code true} if the user has the named privilege, or {@code false} otherwise

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Read the wrapped SQLException cause to identify the true failure (privilege, timeout, protocol).
  2. Run `SHOW VARIABLES LIKE 'gtid_purged'` with the connector's DB user to confirm access and non-empty results.
  3. Ensure the connector user has the needed privileges (SELECT on mysql.* views or at least SHOW VARIABLES access).
  4. Verify GTID_MODE=ON on the server (and replicas) since purged-GTID logic assumes GTID replication.
  5. Restore connectivity (check host/port/firewall/TLS) and restart the connector task.

Example fix

// before
throw new ConnectException("Unexpected error while connecting to MySQL and looking at gtid_purged variable: ", e);
// after: actionable message with host and cause
throw new ConnectException("Failed to read gtid_purged from " + hostname() + ": " + e.getMessage(), e);
Defensive patterns

Strategy: validation

Validate before calling

// Ensure gtid_purged is readable and GTID is on, before starting:
try (Connection c = DriverManager.getConnection(jdbcUrl, user, pass);
     Statement s = c.createStatement();
     ResultSet rs = s.executeQuery("SHOW VARIABLES WHERE Variable_name IN ('gtid_purged','gtid_mode')")) {
    Map<String,String> vars = new HashMap<>();
    while (rs.next()) vars.put(rs.getString(1), rs.getString(2));
    if (!"ON".equalsIgnoreCase(vars.get("gtid_mode")))
        throw new IllegalStateException("GTID_MODE must be ON");
}

Type guard

static boolean hasSqlCause(ConnectException ce) {
    return ce.getCause() instanceof java.sql.SQLException;
}

Try / catch

try {
    engine.start();
} catch (org.apache.kafka.connect.errors.ConnectException e) {
    if (e.getMessage().contains("gtid_purged")) {
        log.error("gtid_purged query failed, cause={}", e.getCause());
        // fatal if privileges; retry if connection loss
    } else { throw e; }
}

Prevention

When it happens

Trigger: Calling purgedGtidSet() when the JDBC connection fails, when SHOW VARIABLES LIKE 'gtid_purged' errors, or when reading the result set throws; caught at MySqlJdbcContext.java:341 and rethrown as ConnectException.

Common situations: User lacks privileges for SHOW VARIABLES; connection dropped by an idle-timeout middlebox; GTID mode disabled on a replica so the variable query path errors; TLS/protocol mismatch between driver and server; MySQL restarted mid-operation.

Understand the failure class

Background: "query failed", "%w: SQL error" — wrapped database query errors in Go libraries explained — this error's family across 3 libraries.

Related errors


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