apache/seatunnel · error · ConnectException

Error reading MySQL variables: ${e.getMessage()}

Error message

Error reading MySQL variables: ${e.getMessage()}

What it means

MySqlJdbcContext.querySystemVariables() runs `SHOW VARIABLES` (optionally filtered by a session-variables list) and loads the results into a map used for charset/system variable configuration. Any SQLException is wrapped in a ConnectException with the message 'Error reading MySQL variables: ' plus the SQLException message; callers include readMySqlCharsetSystemVariables, readMySqlSystemVariables, and sessionVariables.

Source

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

        try {
            jdbc.connect()
                    .query(
                            statement,
                            rs -> {
                                while (rs.next()) {
                                    String varName = rs.getString(1);
                                    String value = rs.getString(2);
                                    if (varName != null && value != null) {
                                        variables.put(varName, value);
                                        logger.debug(
                                                "\t{} = {}",
                                                Strings.pad(varName, 45, ' '),
                                                Strings.pad(value, 45, ' '));
                                    }
                                }
                            });
        } catch (SQLException e) {
            throw new ConnectException("Error reading MySQL variables: " + e.getMessage(), e);
        }

        return variables;
    }

    /**
     * Read the MySQL default character sets for exisiting databases.
     *
     * @return the map of database names with their default character sets; never null
     */
    protected Map<String, DatabaseLocales> readDatabaseCollations() {
        logger.debug("Reading default database charsets");
        try {
            return jdbc.connect()
                    .queryAndMap(
                            "SELECT schema_name, default_character_set_name, default_collation_name FROM information_schema.schemata",
                            rs -> {
                                final Map<String, DatabaseLocales> charsets = new HashMap<>();

View on GitHub (pinned to cf67b549a7)

Solutions

  1. Read the embedded e.getMessage() (appended to this error) for the specific MySQL error and fix it.
  2. Verify the connector user can run `SHOW VARIABLES` (or the filtered variant) with the same credentials.
  3. Increase wait_timeout/interactive_timeout or enable JDBC keepalive/validation to survive idle periods.
  4. Check server health (load, max_connections) and network path between connector and MySQL.
  5. Restart the connector task to obtain a fresh connection after a transient failure.

Example fix

// before
throw new ConnectException("Error reading MySQL variables: " + e.getMessage(), e);
// after: add server context while keeping the SQL error detail
throw new ConnectException("Error reading MySQL variables from " + hostname() + ": " + e.getMessage(), e);
Defensive patterns

Strategy: try-catch

Validate before calling

// Smoke-test SHOW VARIABLES access before launching the job:
try (Connection c = DriverManager.getConnection(jdbcUrl, user, pass);
     Statement s = c.createStatement();
     ResultSet rs = s.executeQuery("SHOW VARIABLES")) {
    int count = 0;
    while (rs.next()) count++;
    if (count == 0) throw new IllegalStateException("SHOW VARIABLES returned nothing");
}

Type guard

static boolean isTransientSqlFailure(ConnectException ce) {
    String m = String.valueOf(ce.getCause() != null ? ce.getCause().getMessage() : "");
    return m.contains("Communications link failure")
        || m.contains("timed out")
        || m.contains("Connection reset");
}

Try / catch

try {
    engine.start();
} catch (org.apache.kafka.connect.errors.ConnectException e) {
    if (e.getMessage().startsWith("Error reading MySQL variables:")) {
        if (isTransientSqlFailure(e)) { retryWithBackoff(); }   // reaped idle connection
        else { throw new IllegalStateException("Fix SHOW VARIABLES access/config: " + e.getMessage(), e); }
    } else { throw e; }
}

Prevention

When it happens

Trigger: Calling sessionVariables(), readMySqlSystemVariables(), or readMySqlCharsetSystemVariables() when the JDBC connection fails, SHOW VARIABLES is denied, or result-set iteration throws; caught at MySqlJdbcContext.java:434 and rethrown as ConnectException.

Common situations: Idle connection killed by MySQL wait_timeout or a firewall before the query; SHOW VARIABLES restricted by hardening policies for the CDC user; server under load causing query timeouts; charset-related variables requested on a server with unusual configuration; driver/server protocol mismatch.

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/2be610d25fd24249. Report an issue: GitHub.