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
JdbcConnection
extension to be used with MySQL Server- Author:
- Jiri Pechanec, Randall Hauch
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
MySqlConnection.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.MySqlConnectionConfiguration
connectionConfig
private static org.slf4j.Logger
LOGGER
private MysqlFieldReader
mysqlFieldReader
private Map<String,String>
originalSystemProperties
private static String
SQL_SHOW_SESSION_VARIABLE_SSL_VERSION
private static String
SQL_SHOW_SYSTEM_VARIABLES
private static String
SQL_SHOW_SYSTEM_VARIABLES_CHARACTER_SET
protected static String
URL_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.void
close()
Connection
connection(boolean executeOnConnect)
String
connectionString()
String
earliestBinlogFilename()
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)
OptionalLong
getEstimatedTableSize(TableId tableId)
protected String
getSessionVariableForSslVersion()
Read the Ssl Version session variable.protected boolean
isBinlogFormatRow()
Determine whether the MySQL server has the row-level binlog enabled.protected boolean
isBinlogRowImageFull()
Determine whether the MySQL server has the binlog_row_image set to 'FULL'.boolean
isGtidModeEnabled()
Determine whether the MySQL server has GTIDs enabled.boolean
isTableIdCaseSensitive()
String
knownGtidSet()
Determine the executed GTID set for MySQL.GtidSet
purgedGtidSet()
Get the purged GTID values from MySQL (gtid_purged value)private Map<String,String>
querySystemVariables(String statement)
String
quotedTableIdString(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 String
setStatementFor(Map<String,String> variables)
protected void
setSystemProperty(String property, Field field, boolean showValueInError)
GtidSet
subtractGtidSet(GtidSet set1, GtidSet set2)
Determine the difference between two sets.boolean
userHasPrivileges(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.MySqlConnectionConfiguration
instance, 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.MySqlConnectionConfiguration
instance, may not be null.
-
-
Method Detail
-
connection
public Connection connection(boolean executeOnConnect) throws SQLException
- Overrides:
connection
in classJdbcConnection
- Throws:
SQLException
-
close
public void close() throws SQLException
- Specified by:
close
in interfaceAutoCloseable
- Overrides:
close
in 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:
false
if the server'sgtid_mode
is set and isOFF
, ortrue
otherwise
-
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:
true
if the user has the named privilege, orfalse
otherwise
-
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:
true
if the server'sbinlog_row_image
is set toFULL
, orfalse
otherwise
-
isBinlogFormatRow
protected boolean isBinlogFormatRow()
Determine whether the MySQL server has the row-level binlog enabled.- Returns:
true
if the server'sbinlog_format
is set toROW
, orfalse
otherwise
-
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:
getColumnValue
in classJdbcConnection
- Throws:
SQLException
-
quotedTableIdString
public String quotedTableIdString(TableId tableId)
- Overrides:
quotedTableIdString
in classJdbcConnection
-
-