diff --git a/src/main/java/com/zendesk/maxwell/MaxwellMysqlStatus.java b/src/main/java/com/zendesk/maxwell/MaxwellMysqlStatus.java index bed51c2c0..f95098fd1 100644 --- a/src/main/java/com/zendesk/maxwell/MaxwellMysqlStatus.java +++ b/src/main/java/com/zendesk/maxwell/MaxwellMysqlStatus.java @@ -34,11 +34,40 @@ public boolean isMaria() { } } + /** + * Generates the appropriate SQL command to retrieve binary log status based on + * the database type and version. + * + * This method checks the database product name and version to determine + * the most suitable SQL command for retrieving binary log status information. + * It supports MySQL and MariaDB, with compatibility for recent version + * requirements: + * + * If an error occurs during metadata retrieval, the method defaults to "SHOW + * MASTER STATUS". + * + * @return a SQL command string to check binary log status + */ public String getShowBinlogSQL() { try { DatabaseMetaData md = connection.getMetaData(); - if ( md.getDatabaseMajorVersion() >= 8 ) { + + String productName = md.getDatabaseProductName(); + + int majorVersion = md.getDatabaseMajorVersion(); + int minorVersion = md.getDatabaseMinorVersion(); + + boolean isMySQL = "MySQL".equalsIgnoreCase(productName); + boolean isMariaDB = "MariaDB".equalsIgnoreCase(productName); + + if (isMySQL && (majorVersion > 8 || (majorVersion == 8 && minorVersion >= 2))) { return "SHOW BINARY LOG STATUS"; + } else if (isMariaDB && (majorVersion > 10 || (majorVersion == 10 && minorVersion >= 5))) { + return "SHOW BINLOG STATUS"; } } catch ( SQLException e ) { }