Package io.debezium.connector.mysql
Class MySqlConnection
- java.lang.Object
-
- io.debezium.jdbc.JdbcConnection
-
- io.debezium.connector.mysql.MySqlConnection
-
- All Implemented Interfaces:
AutoCloseable
public class MySqlConnection extends io.debezium.jdbc.JdbcConnectionCopied from Debezium project(1.9.8.final) to add custom jdbc properties in the jdbc url. The new parameterMySqlConnectionConfiguration(Configuration config, Properties jdbcProperties)in the constructor ofMySqlConnection.MySqlConnectionConfigurationwill be used to generate the jdbc url pattern, and may overwrite the default value.Add field
urlPatterninMySqlConnectionand remove old pattern.Added MySQL 8.4+ compatible probing fields
MYSQL_CLASSIC_SHOW_BINARY_LOG_STATEMENT,MYSQL_NEW_SHOW_BINARY_LOG_STATEMENT, andshowBinaryLogStatement.Init
urlPatternusing the url pattern fromMySqlConnection.MySqlConnectionConfiguration.Generate the connection string by the new field
urlPattern.Add new constant and field
urlPatterntoMySqlConnection.MySqlConnectionConfiguration.Init new field
urlPatterninMySqlConnection.MySqlConnectionConfiguration.Add utility methods helping to generate the url pattern and add default values.
Added utility method
getShowBinaryLogStatement()andprobeShowBinaryLogStatement()for MySQL 8.4 compatibility.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMySqlConnection.MySqlConnectionConfigurationConnection configuration to create aMySqlConnection.-
Nested classes/interfaces inherited from class io.debezium.jdbc.JdbcConnection
io.debezium.jdbc.JdbcConnection.BlockingMultiResultSetConsumer, io.debezium.jdbc.JdbcConnection.BlockingResultSetConsumer, io.debezium.jdbc.JdbcConnection.CallPreparer, io.debezium.jdbc.JdbcConnection.ConnectionFactory, io.debezium.jdbc.JdbcConnection.MultiResultSetConsumer, io.debezium.jdbc.JdbcConnection.Operations, io.debezium.jdbc.JdbcConnection.ParameterResultSetConsumer, io.debezium.jdbc.JdbcConnection.ResultSetConsumer, io.debezium.jdbc.JdbcConnection.ResultSetExtractor<T extends Object>, io.debezium.jdbc.JdbcConnection.ResultSetMapper<T extends Object>, io.debezium.jdbc.JdbcConnection.StatementFactory, io.debezium.jdbc.JdbcConnection.StatementPreparer
-
-
Constructor Summary
Constructors Constructor Description MySqlConnection(MySqlConnection.MySqlConnectionConfiguration connectionConfig)Creates a new connection using the supplied configuration.MySqlConnection(MySqlConnection.MySqlConnectionConfiguration connectionConfig, io.debezium.connector.mysql.MySqlFieldReader fieldReader)Creates a new connection using the supplied configuration.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description List<String>availableBinlogFiles()Query the database server to get the list of the binlog files availble.voidclose()MySqlConnection.MySqlConnectionConfigurationconnectionConfig()StringconnectionString()StringearliestBinlogFilename()Determine the earliest binlog filename that is still available in the server.<T extends io.debezium.schema.DatabaseSchema<io.debezium.relational.TableId>>
ObjectgetColumnValue(ResultSet rs, int columnIndex, io.debezium.relational.Column column, io.debezium.relational.Table table, T schema)OptionalLonggetEstimatedTableSize(io.debezium.relational.TableId tableId)static StringgetJavaEncodingForMysqlCharSet(String mysqlCharsetName)protected StringgetSessionVariableForSslVersion()Read the Ssl Version session variable.StringgetShowBinaryLogStatement()protected booleanisBinlogFormatRow()Determine whether the MySQL server has the row-level binlog enabled.protected booleanisBinlogRowImageFull()Determine whether the MySQL server has the binlog_row_image set to 'FULL'.booleanisGtidModeEnabled()Determine whether the MySQL server has GTIDs enabled.booleanisTableIdCaseSensitive()StringknownGtidSet()Determine the executed GTID set for MySQL.io.debezium.connector.mysql.GtidSetpurgedGtidSet()Get the purged GTID values from MySQL (gtid_purged value).StringquotedTableIdString(io.debezium.relational.TableId tableId)protected Map<String,io.debezium.connector.mysql.legacy.MySqlJdbcContext.DatabaseLocales>readDatabaseCollations()Read the MySQL default character sets for exisiting databases.protected Map<String,String>readMySqlCharsetSystemVariables()Read the MySQL charset-related system variables.protected Map<String,String>readMySqlSystemVariables()Read the MySQL system variables.protected StringsetStatementFor(Map<String,String> variables)protected voidsetSystemProperty(String property, io.debezium.config.Field field, boolean showValueInError)io.debezium.connector.mysql.GtidSetsubtractGtidSet(io.debezium.connector.mysql.GtidSet set1, io.debezium.connector.mysql.GtidSet set2)Determine the difference between two sets.booleanuserHasPrivileges(String grantName)Determine if the current user has the named privilege.-
Methods inherited from class io.debezium.jdbc.JdbcConnection
buildSelectWithRowLimits, call, commit, config, connect, connection, connection, connectionString, database, execute, execute, executeWithoutCommitting, getColumnsDetails, getCurrentTimestamp, isConnected, isNullable, isTableType, isTableUniqueIndexIncluded, isValid, loadKeyStore, overrideColumn, parseSqlStatementString, patternBasedFactory, patternBasedFactory, prepareQuery, prepareQuery, prepareQuery, prepareQuery, prepareQuery, prepareQueryAndMap, prepareQueryWithBlockingConsumer, prepareUpdate, print, print, query, query, queryAndMap, queryAndMap, querySingleValue, queryWithBlockingConsumer, quotedColumnIdString, readAllCatalogNames, readAllSchemaNames, readAllTableNames, readPrimaryKeyNames, readPrimaryKeyOrUniqueIndexNames, readSchema, readTableColumn, readTableNames, readTablePreparedStatement, readTableStatement, readTableUniqueIndices, resolveCatalogName, resolveJdbcType, resolveNativeType, rollback, rowToArray, setAutoCommit, singleResultMapper, supportedTableTypes, tableTypes, username
-
-
-
-
Constructor Detail
-
MySqlConnection
public MySqlConnection(MySqlConnection.MySqlConnectionConfiguration connectionConfig, io.debezium.connector.mysql.MySqlFieldReader fieldReader)
Creates a new connection using the supplied configuration.- Parameters:
connectionConfig-MySqlConnection.MySqlConnectionConfigurationinstance, may not be null.fieldReader- binary or text protocol based readers
-
MySqlConnection
public MySqlConnection(MySqlConnection.MySqlConnectionConfiguration connectionConfig)
Creates a new connection using the supplied configuration.- Parameters:
connectionConfig-MySqlConnection.MySqlConnectionConfigurationinstance, may not be null.
-
-
Method Detail
-
close
public void close() throws SQLException- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classio.debezium.jdbc.JdbcConnection- Throws:
SQLException
-
readMySqlCharsetSystemVariables
protected Map<String,String> readMySqlCharsetSystemVariables()
Read the MySQL charset-related system variables.- Returns:
- the system variables that are related to server character sets; never null
-
readMySqlSystemVariables
protected Map<String,String> readMySqlSystemVariables()
Read the MySQL system variables.- Returns:
- the system variables that are related to server character sets; never null
-
setSystemProperty
protected void setSystemProperty(String property, io.debezium.config.Field field, boolean showValueInError)
-
getSessionVariableForSslVersion
protected String getSessionVariableForSslVersion()
Read the Ssl Version session variable.- Returns:
- the session variables that are related to sessions ssl version
-
isGtidModeEnabled
public boolean isGtidModeEnabled()
Determine whether the MySQL server has GTIDs enabled.- Returns:
falseif the server'sgtid_modeis set and isOFF, ortrueotherwise
-
knownGtidSet
public String knownGtidSet()
Determine the executed GTID set for MySQL.- Returns:
- the string representation of MySQL's GTID sets; never null but an empty string if the server does not use GTIDs
-
subtractGtidSet
public io.debezium.connector.mysql.GtidSet subtractGtidSet(io.debezium.connector.mysql.GtidSet set1, io.debezium.connector.mysql.GtidSet set2)Determine the difference between two sets.- Returns:
- a subtraction of two GTID sets; never null
-
purgedGtidSet
public io.debezium.connector.mysql.GtidSet purgedGtidSet()
Get the purged GTID values from MySQL (gtid_purged value).- Returns:
- A GTID set; may be empty if not using GTIDs or none have been purged yet
-
userHasPrivileges
public boolean userHasPrivileges(String grantName)
Determine if the current user has the named privilege. Note that if the user has the "ALL" privilege this method returnstrue.- Parameters:
grantName- the name of the MySQL privilege; may not be null- Returns:
trueif the user has the named privilege, orfalseotherwise
-
earliestBinlogFilename
public String earliestBinlogFilename()
Determine the earliest binlog filename that is still available in the server.- Returns:
- the name of the earliest binlog filename, or null if there are none.
-
isBinlogRowImageFull
protected boolean isBinlogRowImageFull()
Determine whether the MySQL server has the binlog_row_image set to 'FULL'.- Returns:
trueif the server'sbinlog_row_imageis set toFULL, orfalseotherwise
-
isBinlogFormatRow
protected boolean isBinlogFormatRow()
Determine whether the MySQL server has the row-level binlog enabled.- Returns:
trueif the server'sbinlog_formatis set toROW, orfalseotherwise
-
availableBinlogFiles
public List<String> availableBinlogFiles()
Query the database server to get the list of the binlog files availble.- Returns:
- list of the binlog files
-
getEstimatedTableSize
public OptionalLong getEstimatedTableSize(io.debezium.relational.TableId tableId)
-
isTableIdCaseSensitive
public boolean isTableIdCaseSensitive()
-
readDatabaseCollations
protected Map<String,io.debezium.connector.mysql.legacy.MySqlJdbcContext.DatabaseLocales> readDatabaseCollations()
Read the MySQL default character sets for exisiting databases.- Returns:
- the map of database names with their default character sets; never null
-
connectionConfig
public MySqlConnection.MySqlConnectionConfiguration connectionConfig()
-
connectionString
public String connectionString()
-
getJavaEncodingForMysqlCharSet
public static String getJavaEncodingForMysqlCharSet(String mysqlCharsetName)
-
getColumnValue
public <T extends io.debezium.schema.DatabaseSchema<io.debezium.relational.TableId>> Object getColumnValue(ResultSet rs, int columnIndex, io.debezium.relational.Column column, io.debezium.relational.Table table, T schema) throws SQLException
- Overrides:
getColumnValuein classio.debezium.jdbc.JdbcConnection- Throws:
SQLException
-
quotedTableIdString
public String quotedTableIdString(io.debezium.relational.TableId tableId)
- Overrides:
quotedTableIdStringin classio.debezium.jdbc.JdbcConnection
-
getShowBinaryLogStatement
public String getShowBinaryLogStatement()
-
-