{"record":{"id":"6687a7def6760b51","repo":"apache/seatunnel","slug":"unexpected-error-while-connecting-to-mysql-and-loo-6687a7","errorCode":null,"errorMessage":"Unexpected error while connecting to MySQL and looking at GTID mode: ","messagePattern":"Unexpected error while connecting to MySQL and looking at GTID mode: ","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":262,"sourceCode":"\n    /**\n     * Determine whether the MySQL server has GTIDs enabled.\n     *\n     * @return {@code false} if the server's {@code gtid_mode} is set and is {@code OFF}, or {@code\n     *     true} otherwise\n     */\n    public boolean isGtidModeEnabled() {\n        AtomicReference<String> mode = new AtomicReference<String>(\"off\");\n        try {\n            jdbc().query(\n                            \"SHOW GLOBAL VARIABLES LIKE 'GTID_MODE'\",\n                            rs -> {\n                                if (rs.next()) {\n                                    mode.set(rs.getString(2));\n                                }\n                            });\n        } catch (SQLException e) {\n            throw new ConnectException(\n                    \"Unexpected error while connecting to MySQL and looking at GTID mode: \", e);\n        }\n\n        return !\"OFF\".equalsIgnoreCase(mode.get());\n    }\n\n    /**\n     * Determine the executed GTID set for MySQL.\n     *\n     * @return the string representation of MySQL's GTID sets; never null but an empty string if the\n     *     server does not use GTIDs\n     */\n    public String knownGtidSet() {\n        AtomicReference<String> gtidSetStr = new AtomicReference<String>();\n        try {\n            jdbc.query(\n                    showMasterStmt,\n                    rs -> {","sourceCodeStart":244,"sourceCodeEnd":280,"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#L244-L280","documentation":"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.","triggerScenarios":"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.","commonSituations":"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).","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."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Probe GTID visibility with the same credentials before starting the job\ntry (Connection c = DriverManager.getConnection(jdbcUrl, user, pass);\n     Statement s = c.createStatement();\n     ResultSet rs = s.executeQuery(\"SELECT @@global.gtid_mode\")) {\n    rs.next();\n    System.out.println(\"gtid_mode=\" + rs.getString(1));\n} // failure here predicts the ConnectException; fix privileges/network first","typeGuard":null,"tryCatchPattern":"try {\n    startCdcSource(config);\n} catch (ConnectException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"GTID mode\")) {\n        log.warn(\"GTID probe failed, will retry after connectivity check\", e.getCause());\n        // transient SQLExceptions (network blip, failover) may be retried with backoff\n        retryWithBackoff(() -> startCdcSource(config), 3);\n    } else {\n        throw e;\n    }\n}","preventionTips":["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."],"tags":["mysql","cdc","jdbc","gtid","sql"],"backgroundTag":"database-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"}