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 JdbcConnection
JdbcConnectionextension to be used with MySQL Server- Author:
- Jiri Pechanec, Randall Hauch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classMySqlConnection.MySqlConnectionConfiguration-
Nested classes/interfaces inherited from class io.debezium.jdbc.JdbcConnection
JdbcConnection.BlockingMultiResultSetConsumer, JdbcConnection.BlockingResultSetConsumer, JdbcConnection.CallPreparer, JdbcConnection.ConnectionFactory, JdbcConnection.MultiResultSetConsumer, JdbcConnection.Operations, JdbcConnection.ParameterResultSetConsumer, JdbcConnection.ResultSetConsumer, JdbcConnection.ResultSetExtractor<T extends Object>, JdbcConnection.ResultSetMapper<T extends Object>, JdbcConnection.StatementFactory, JdbcConnection.StatementPreparer
-
-
Field Summary
Fields Modifier and Type Field Description private MySqlConnection.MySqlConnectionConfigurationconnectionConfigprivate static org.slf4j.LoggerLOGGERprivate MysqlFieldReadermysqlFieldReaderprivate Map<String,String>originalSystemPropertiesprivate static StringSQL_SHOW_SESSION_VARIABLE_SSL_VERSIONprivate static StringSQL_SHOW_SYSTEM_VARIABLESprivate static StringSQL_SHOW_SYSTEM_VARIABLES_CHARACTER_SETprotected static StringURL_PATTERN
-
Constructor Summary
Constructors Constructor Description MySqlConnection(MySqlConnection.MySqlConnectionConfiguration connectionConfig)Creates a new connection using the supplied configuration.MySqlConnection(MySqlConnection.MySqlConnectionConfiguration connectionConfig, MysqlFieldReader fieldReader)Creates a new connection using the supplied configuration.
-
Method Summary
All 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()Connectionconnection(boolean executeOnConnect)StringconnectionString()StringearliestBinlogFilename()Determine the earliest binlog filename that is still available in the server.<T extends DatabaseSchema<TableId>>
ObjectgetColumnValue(ResultSet rs, int columnIndex, Column column, Table table, T schema)OptionalLonggetEstimatedTableSize(TableId tableId)protected StringgetSessionVariableForSslVersion()Read the Ssl Version session variable.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.GtidSetpurgedGtidSet()Get the purged GTID values from MySQL (gtid_purged value)private Map<String,String>querySystemVariables(String statement)StringquotedTableIdString(TableId tableId)protected Map<String,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, Field field, boolean showValueInError)GtidSetsubtractGtidSet(GtidSet set1, 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, connectionString, database, execute, execute, executeWithoutCommitting, getDefaultValue, isConnected, isNullable, isTableUniqueIndexIncluded, parseSqlStatementString, patternBasedFactory, patternBasedFactory, prepareQuery, prepareQuery, prepareQuery, prepareQuery, prepareQueryAndMap, prepareQueryWithBlockingConsumer, prepareUpdate, print, print, query, query, queryAndMap, queryAndMap, querySingleValue, queryWithBlockingConsumer, readAllCatalogNames, readAllSchemaNames, readAllTableNames, readPrimaryKeyNames, readPrimaryKeyOrUniqueIndexNames, readSchema, readTableColumn, readTableNames, readTablePreparedStatement, readTableStatement, readTableUniqueIndices, resolveJdbcType, resolveNativeType, rollback, rowToArray, setAutoCommit, singleResultMapper, tableTypes, username
-
-
-
-
Field Detail
-
LOGGER
private static org.slf4j.Logger LOGGER
-
SQL_SHOW_SYSTEM_VARIABLES
private static final String SQL_SHOW_SYSTEM_VARIABLES
- See Also:
- Constant Field Values
-
SQL_SHOW_SYSTEM_VARIABLES_CHARACTER_SET
private static final String SQL_SHOW_SYSTEM_VARIABLES_CHARACTER_SET
- See Also:
- Constant Field Values
-
SQL_SHOW_SESSION_VARIABLE_SSL_VERSION
private static final String SQL_SHOW_SESSION_VARIABLE_SSL_VERSION
- See Also:
- Constant Field Values
-
URL_PATTERN
protected static final String URL_PATTERN
- See Also:
- Constant Field Values
-
connectionConfig
private final MySqlConnection.MySqlConnectionConfiguration connectionConfig
-
mysqlFieldReader
private final MysqlFieldReader mysqlFieldReader
-
-
Constructor Detail
-
MySqlConnection
public MySqlConnection(MySqlConnection.MySqlConnectionConfiguration connectionConfig, 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
-
connection
public Connection connection(boolean executeOnConnect) throws SQLException
- Overrides:
connectionin classJdbcConnection- Throws:
SQLException
-
close
public void close() throws SQLException- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classJdbcConnection- 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, 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 GtidSet subtractGtidSet(GtidSet set1, GtidSet set2)
Determine the difference between two sets.- Returns:
- a subtraction of two GTID sets; never null
-
purgedGtidSet
public 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(TableId tableId)
-
isTableIdCaseSensitive
public boolean isTableIdCaseSensitive()
-
readDatabaseCollations
protected Map<String,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
-
connectionString
public String connectionString()
-
getColumnValue
public <T extends DatabaseSchema<TableId>> Object getColumnValue(ResultSet rs, int columnIndex, Column column, Table table, T schema) throws SQLException
- Overrides:
getColumnValuein classJdbcConnection- Throws:
SQLException
-
quotedTableIdString
public String quotedTableIdString(TableId tableId)
- Overrides:
quotedTableIdStringin classJdbcConnection
-
-