{"record":{"id":"2be610d25fd24249","repo":"apache/seatunnel","slug":"error-reading-mysql-variables-e-getmessage","errorCode":null,"errorMessage":"Error reading MySQL variables: ${e.getMessage()}","messagePattern":"Error reading MySQL variables: (.+?)","errorType":"exception","errorClass":"ConnectException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-cdc/connector-cdc-mysql/src/main/java/io/debezium/connector/mysql/legacy/MySqlJdbcContext.java","lineNumber":434,"sourceCode":"        try {\n            jdbc.connect()\n                    .query(\n                            statement,\n                            rs -> {\n                                while (rs.next()) {\n                                    String varName = rs.getString(1);\n                                    String value = rs.getString(2);\n                                    if (varName != null && value != null) {\n                                        variables.put(varName, value);\n                                        logger.debug(\n                                                \"\\t{} = {}\",\n                                                Strings.pad(varName, 45, ' '),\n                                                Strings.pad(value, 45, ' '));\n                                    }\n                                }\n                            });\n        } catch (SQLException e) {\n            throw new ConnectException(\"Error reading MySQL variables: \" + e.getMessage(), e);\n        }\n\n        return variables;\n    }\n\n    /**\n     * Read the MySQL default character sets for exisiting databases.\n     *\n     * @return the map of database names with their default character sets; never null\n     */\n    protected Map<String, DatabaseLocales> readDatabaseCollations() {\n        logger.debug(\"Reading default database charsets\");\n        try {\n            return jdbc.connect()\n                    .queryAndMap(\n                            \"SELECT schema_name, default_character_set_name, default_collation_name FROM information_schema.schemata\",\n                            rs -> {\n                                final Map<String, DatabaseLocales> charsets = new HashMap<>();","sourceCodeStart":416,"sourceCodeEnd":452,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-cdc/connector-cdc-mysql/src/main/java/io/debezium/connector/mysql/legacy/MySqlJdbcContext.java#L416-L452","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Read the embedded e.getMessage() (appended to this error) for the specific MySQL error and fix it.","Verify the connector user can run `SHOW VARIABLES` (or the filtered variant) with the same credentials.","Increase wait_timeout/interactive_timeout or enable JDBC keepalive/validation to survive idle periods.","Check server health (load, max_connections) and network path between connector and MySQL.","Restart the connector task to obtain a fresh connection after a transient failure."],"exampleFix":"// before\nthrow new ConnectException(\"Error reading MySQL variables: \" + e.getMessage(), e);\n// after: add server context while keeping the SQL error detail\nthrow new ConnectException(\"Error reading MySQL variables from \" + hostname() + \": \" + e.getMessage(), e);","handlingStrategy":"try-catch","validationCode":"// Smoke-test SHOW VARIABLES access before launching the job:\ntry (Connection c = DriverManager.getConnection(jdbcUrl, user, pass);\n     Statement s = c.createStatement();\n     ResultSet rs = s.executeQuery(\"SHOW VARIABLES\")) {\n    int count = 0;\n    while (rs.next()) count++;\n    if (count == 0) throw new IllegalStateException(\"SHOW VARIABLES returned nothing\");\n}","typeGuard":"static boolean isTransientSqlFailure(ConnectException ce) {\n    String m = String.valueOf(ce.getCause() != null ? ce.getCause().getMessage() : \"\");\n    return m.contains(\"Communications link failure\")\n        || m.contains(\"timed out\")\n        || m.contains(\"Connection reset\");\n}","tryCatchPattern":"try {\n    engine.start();\n} catch (org.apache.kafka.connect.errors.ConnectException e) {\n    if (e.getMessage().startsWith(\"Error reading MySQL variables:\")) {\n        if (isTransientSqlFailure(e)) { retryWithBackoff(); }   // reaped idle connection\n        else { throw new IllegalStateException(\"Fix SHOW VARIABLES access/config: \" + e.getMessage(), e); }\n    } else { throw e; }\n}","preventionTips":["Keep the JDBC session alive: raise wait_timeout or enable keepalive/validation queries.","Confirm the CDC user can execute SHOW VARIABLES in every environment (dev/staging/prod).","Pre-flight `SHOW VARIABLES` with the exact JDBC URL (TLS settings included) before deploys.","Alert on MySQL restarts/max_connections exhaustion, common root causes of this failure.","Include the SQLException message (already embedded here) in your log triage runbook."],"tags":["mysql","jdbc","variables","cdc","sql"],"backgroundTag":"sql-query-failed","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}