MySQL database type plugin for Flyway database migration engine providing specialized MySQL and MariaDB support for schema migrations.
—
Database operation classes provide MySQL and MariaDB-specific implementations for database connections, version detection, and specialized behavior for different MySQL environments including Percona XtraDB Cluster, WSREP clusters, and GTID consistency modes.
Core MySQL database implementation with environment detection and specialized behavior for various MySQL deployments.
/**
* MySQL-specific database implementation
* Handles MySQL-specific behavior, version detection, and cluster environments
*/
public class MySQLDatabase extends Database<MySQLConnection> {
/**
* Creates a new MySQL database instance
* @param configuration Flyway configuration
* @param jdbcConnectionFactory JDBC connection factory
* @param statementInterceptor Statement interceptor for monitoring
*/
public MySQLDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor);
/**
* Returns WSREP status for cluster environments
* @return true if WSREP_ON=ON (for MariaDB clusters)
*/
public boolean isWsrepOn();
/**
* Extracts MySQL version from SELECT VERSION() output
* @param selectVersionOutput Raw version string from database
* @return Parsed MigrationVersion
* @throws FlywayException if version cannot be determined
*/
public static MigrationVersion extractMySQLVersionFromString(String selectVersionOutput);
/**
* Extracts MariaDB version from SELECT VERSION() output
* Handles both standard MariaDB and MaxScale proxy scenarios
* @param selectVersionOutput Raw version string from database
* @return Parsed MigrationVersion
* @throws FlywayException if version cannot be determined
*/
public static MigrationVersion extractMariaDBVersionFromString(String selectVersionOutput);
/**
* Detects if running in Percona XtraDB Cluster with strict mode
* @param jdbcTemplate JDBC template for queries
* @return true if PXC strict mode is ENFORCING or MASTER
*/
public static boolean isRunningInPerconaXtraDBClusterWithStrictMode(JdbcTemplate jdbcTemplate);
/**
* Detects if WSREP is enabled (for MariaDB Galera clusters)
* @param jdbcTemplate JDBC template for queries
* @return true if @@GLOBAL.WSREP_ON is ON
*/
static boolean isWsrepOn(JdbcTemplate jdbcTemplate);
/**
* Detects if GTID consistency is enforced
* @param jdbcTemplate JDBC template for queries
* @return true if @@GLOBAL.ENFORCE_GTID_CONSISTENCY is ON
*/
public static boolean isRunningInGTIDConsistencyMode(JdbcTemplate jdbcTemplate);
/**
* Returns the constraint name for MySQL primary keys
* @param tableName Name of the table
* @return Quoted constraint name in format `tableName_pk`
*/
protected String getConstraintName(String tableName);
/**
* Creates MySQL-specific connection instance
* @param connection Raw JDBC connection
* @return MySQLConnection instance
*/
@Override
protected MySQLConnection doGetConnection(Connection connection);
/**
* Determines database version from SELECT VERSION() output
* Handles both MySQL and MariaDB version detection
* @return Parsed MigrationVersion
*/
@Override
protected MigrationVersion determineVersion();
/**
* Ensures MySQL/MariaDB version is supported by Flyway
* @param configuration Flyway configuration for edition checks
*/
@Override
public void ensureSupported(Configuration configuration);
/**
* Returns current database user
* @return Username portion from USER() function
* @throws SQLException if query fails
*/
@Override
protected String doGetCurrentUser() throws SQLException;
/**
* MySQL does not support DDL transactions
* @return false (MySQL auto-commits DDL)
*/
@Override
public boolean supportsDdlTransactions();
/**
* Returns MySQL boolean true representation
* @return "1"
*/
@Override
public String getBooleanTrue();
/**
* Returns MySQL boolean false representation
* @return "0"
*/
@Override
public String getBooleanFalse();
/**
* Returns MySQL identifier quote character
* @return "`" (backtick)
*/
@Override
public String getOpenQuote();
/**
* Returns MySQL identifier quote character
* @return "`" (backtick)
*/
@Override
public String getCloseQuote();
/**
* MySQL treats database as schema
* @return true
*/
@Override
public boolean catalogIsSchema();
/**
* Determines if single connection should be used
* @return false for PXC strict mode, true otherwise
*/
@Override
public boolean useSingleConnection();
/**
* Detects cloud hosting environment
* @return "AWS RDS" if detected, otherwise default hosting
*/
@Override
public String getDatabaseHosting();
/**
* Determines if CREATE TABLE AS SELECT is allowed
* @return false for PXC strict mode and GTID consistency, true otherwise
*/
protected boolean isCreateTableAsSelectAllowed();
// Package-private methods for internal use
boolean isMySQL();
boolean isMariaDB();
boolean isPxcStrict();
}Usage Examples:
// Automatic creation via DatabaseType
MySQLDatabaseType dbType = new MySQLDatabaseType();
MySQLDatabase database = (MySQLDatabase) dbType.createDatabase(configuration, jdbcFactory, interceptor);
// Environment detection
boolean isCluster = database.isWsrepOn();
boolean hasGtid = MySQLDatabase.isRunningInGTIDConsistencyMode(jdbcTemplate);
// Version parsing
String versionOutput = "8.0.28-0ubuntu0.20.04.3";
MigrationVersion version = MySQLDatabase.extractMySQLVersionFromString(versionOutput);
String mariaVersionOutput = "10.6.7-MariaDB-2ubuntu1.1";
MigrationVersion mariaVersion = MySQLDatabase.extractMariaDBVersionFromString(mariaVersionOutput);MariaDB-specific database implementation extending MySQL database with MariaDB-specific behavior.
/**
* MariaDB-specific database implementation
* Extends MySQLDatabase with MariaDB-specific behavior
*/
public class MariaDBDatabase extends MySQLDatabase {
/**
* Creates a new MariaDB database instance
* @param configuration Flyway configuration
* @param jdbcConnectionFactory JDBC connection factory
* @param statementInterceptor Statement interceptor for monitoring
*/
public MariaDBDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor);
/**
* Returns constraint name format for MariaDB
* MariaDB returns empty string for constraint names
* @param tableName Name of the table
* @return Empty string (MariaDB-specific behavior)
*/
@Override
protected String getConstraintName(String tableName);
/**
* Ensures MariaDB version is supported
* Checks minimum version requirements and edition compatibility
* @param configuration Flyway configuration for edition checks
*/
@Override
public void ensureSupported(Configuration configuration);
}Usage Example:
// Automatic creation via MariaDBDatabaseType
MariaDBDatabaseType dbType = new MariaDBDatabaseType();
MariaDBDatabase database = (MariaDBDatabase) dbType.createDatabase(configuration, jdbcFactory, interceptor);
// MariaDB-specific behavior
String constraintName = database.getConstraintName("my_table"); // Returns ""Detects PXC strict mode which affects certain operations:
// Check for PXC strict mode
boolean isPxcStrict = MySQLDatabase.isRunningInPerconaXtraDBClusterWithStrictMode(jdbcTemplate);
// PXC strict mode affects:
// - CREATE TABLE AS SELECT operations (not allowed)
// - Single connection usage (required)PXC Strict Mode Values:
ENFORCING - Strict mode enabledMASTER - Master strict modeDetects MariaDB Galera cluster environments:
// Check for WSREP (MariaDB Galera)
boolean isWsrepOn = MySQLDatabase.isWsrepOn(jdbcTemplate);
// WSREP affects various operations and cluster behaviorDetects MySQL GTID consistency enforcement:
// Check for GTID consistency
boolean hasGtidConsistency = MySQLDatabase.isRunningInGTIDConsistencyMode(jdbcTemplate);
// GTID consistency affects:
// - CREATE TABLE AS SELECT operations (not allowed)
// - Transaction handlingSupports various MySQL version formats:
// Standard MySQL versions
String version1 = "8.0.28";
String version2 = "5.7.36-log";
String version3 = "8.0.28-0ubuntu0.20.04.3";
MigrationVersion v1 = MySQLDatabase.extractMySQLVersionFromString(version1); // 8.0
MigrationVersion v2 = MySQLDatabase.extractMySQLVersionFromString(version2); // 5.7
MigrationVersion v3 = MySQLDatabase.extractMySQLVersionFromString(version3); // 8.0Handles MariaDB-specific version formats:
// Standard MariaDB
String mariaVersion1 = "10.6.7-MariaDB";
String mariaVersion2 = "10.5.15-1-MariaDB-enterprise";
// MaxScale proxy scenario
String maxScaleVersion = "10.6.7-2 2.5.11-maxscale";
MigrationVersion mv1 = MySQLDatabase.extractMariaDBVersionFromString(mariaVersion1); // 10.6
MigrationVersion mv2 = MySQLDatabase.extractMariaDBVersionFromString(mariaVersion2); // 10.5
MigrationVersion mv3 = MySQLDatabase.extractMariaDBVersionFromString(maxScaleVersion); // 10.6// MySQL does not support DDL transactions
database.supportsDdlTransactions(); // Returns false// MySQL uses backticks for identifiers
String openQuote = database.getOpenQuote(); // Returns "`"
String closeQuote = database.getCloseQuote(); // Returns "`"// MySQL boolean representation
String trueValue = database.getBooleanTrue(); // Returns "1"
String falseValue = database.getBooleanFalse(); // Returns "0"// MySQL treats catalog as schema
boolean catalogIsSchema = database.catalogIsSchema(); // Returns true// Connection usage depends on environment
boolean useSingleConnection = database.useSingleConnection();
// Returns false for PXC strict mode, true otherwise// Check if running on AWS RDS
String hosting = database.getDatabaseHosting();
// Returns "AWS RDS" if detected, otherwise default hostingDetection is based on:
The database classes provide specialized table creation scripts:
// Get raw CREATE TABLE script for history table
Table historyTable = schema.getTable("flyway_schema_history");
String createScript = database.getRawCreateScript(historyTable, false);
// For baseline scenarios
String baselineScript = database.getRawCreateScript(historyTable, true);Features:
Install with Tessl CLI
npx tessl i tessl/maven-org-flywaydb--flyway-mysql