MySQL database type plugin for Flyway database migration engine providing specialized MySQL and MariaDB support for schema migrations.
—
Database type plugins are the primary entry points for MySQL and MariaDB support in Flyway. They are automatically discovered through Java's Service Provider Interface (SPI) and handle URL recognition, driver selection, and factory methods for creating database-specific instances.
The primary MySQL database type plugin that handles MySQL database connections and creates MySQL-specific instances.
/**
* MySQL database type plugin for Flyway
* Automatically registered via META-INF/services/org.flywaydb.core.extensibility.Plugin
*/
public class MySQLDatabaseType extends BaseDatabaseType {
/**
* Returns the database type name
* @return "MySQL"
*/
public String getName();
/**
* Returns supported database engines
* @return List containing "MySQL", "PerconaXtraDbCluster", "TiDb", "AuroraMySql"
*/
public List<String> getSupportedEngines();
/**
* Returns the null type for this database
* @return Types.VARCHAR
*/
public int getNullType();
/**
* Determines if this database type can handle the given JDBC URL
* @param url JDBC URL to test
* @return true if URL is MySQL-compatible
*/
public boolean handlesJDBCUrl(String url);
/**
* Returns the appropriate JDBC driver class for the URL
* @param url JDBC URL
* @param classLoader Class loader for driver loading
* @return Driver class name (e.g., "com.mysql.cj.jdbc.Driver")
*/
public String getDriverClass(String url, ClassLoader classLoader);
/**
* Returns backup driver classes if primary driver is not available
* @param url JDBC URL
* @param classLoader Class loader for driver loading
* @return Backup driver class name or null
*/
public String getBackupDriverClass(String url, ClassLoader classLoader);
/**
* Determines if database product name/version matches MySQL
* @param databaseProductName Database product name from JDBC metadata
* @param databaseProductVersion Database version from JDBC metadata
* @param connection JDBC connection for additional checks
* @return true if database is MySQL
*/
public boolean handlesDatabaseProductNameAndVersion(String databaseProductName, String databaseProductVersion, Connection connection);
/**
* Factory method to create MySQL database instance
* @param configuration Flyway configuration
* @param jdbcConnectionFactory JDBC connection factory
* @param statementInterceptor Statement interceptor for monitoring
* @return MySQLDatabase instance
*/
public Database createDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor);
/**
* Factory method to create MySQL parser instance
* @param configuration Flyway configuration
* @param resourceProvider Resource provider for SQL scripts
* @param parsingContext Parsing context and settings
* @return MySQLParser instance
*/
public Parser createParser(Configuration configuration, ResourceProvider resourceProvider, ParsingContext parsingContext);
/**
* Sets default connection properties for MySQL connections
* @param url JDBC URL
* @param props Properties to modify
* @param classLoader Class loader context
*/
public void setDefaultConnectionProps(String url, Properties props, ClassLoader classLoader);
/**
* Handles external authentication properties (e.g., option files)
* @param url JDBC URL
* @param username Database username
* @return Properties with external authentication settings
*/
public Properties getExternalAuthProperties(String url, String username);
/**
* Returns extended error message for driver instantiation failures
* @return Error message with MySQL connector/J download instructions
*/
public String instantiateClassExtendedErrorMessage();
}Constants:
// Driver class constants
private static final String MYSQL_LEGACY_JDBC_DRIVER = "com.mysql.jdbc.Driver";
private static final String MARIADB_JDBC_DRIVER = "org.mariadb.jdbc.Driver";
}Usage Example:
// Automatic usage via Flyway
Flyway flyway = Flyway.configure()
.dataSource("jdbc:mysql://localhost:3306/mydb", "user", "password")
.load(); // MySQLDatabaseType automatically discovered and used
// Direct usage (advanced)
MySQLDatabaseType dbType = new MySQLDatabaseType();
boolean canHandle = dbType.handlesJDBCUrl("jdbc:mysql://localhost:3306/test");
String driverClass = dbType.getDriverClass("jdbc:mysql://localhost:3306/test", Thread.currentThread().getContextClassLoader());MariaDB-specific database type plugin with higher priority than MySQL to ensure MariaDB URLs are handled correctly.
/**
* MariaDB database type plugin for Flyway
* Has higher priority than MySQL to handle MariaDB-specific features
* Automatically registered via META-INF/services/org.flywaydb.core.extensibility.Plugin
*/
public class MariaDBDatabaseType extends BaseDatabaseType {
/**
* Returns the database type name
* @return "MariaDB"
*/
public String getName();
/**
* Returns priority for database type selection
* @return 1 (higher than MySQL's default priority)
*/
public int getPriority();
/**
* Returns the null type for this database
* @return Types.VARCHAR
*/
public int getNullType();
/**
* Determines if this database type can handle the given JDBC URL
* @param url JDBC URL to test
* @return true if URL is MariaDB-compatible
*/
public boolean handlesJDBCUrl(String url);
/**
* Returns the appropriate JDBC driver class for MariaDB
* @param url JDBC URL
* @param classLoader Class loader for driver loading
* @return "org.mariadb.jdbc.Driver" or P6Spy wrapper
*/
public String getDriverClass(String url, ClassLoader classLoader);
/**
* Determines if database product matches MariaDB
* Handles various MariaDB detection scenarios including Azure Database for MariaDB
* @param databaseProductName Database product name from JDBC metadata
* @param databaseProductVersion Database version from JDBC metadata
* @param connection JDBC connection for SELECT VERSION() check
* @return true if database is MariaDB
*/
public boolean handlesDatabaseProductNameAndVersion(String databaseProductName, String databaseProductVersion, Connection connection);
/**
* Factory method to create MariaDB database instance
* @param configuration Flyway configuration
* @param jdbcConnectionFactory JDBC connection factory
* @param statementInterceptor Statement interceptor for monitoring
* @return MariaDBDatabase instance
*/
public Database createDatabase(Configuration configuration, JdbcConnectionFactory jdbcConnectionFactory, StatementInterceptor statementInterceptor);
/**
* Factory method to create MariaDB parser instance
* @param configuration Flyway configuration
* @param resourceProvider Resource provider for SQL scripts
* @param parsingContext Parsing context and settings
* @return MariaDBParser instance
*/
public Parser createParser(Configuration configuration, ResourceProvider resourceProvider, ParsingContext parsingContext);
/**
* Sets default connection properties for MariaDB connections
* @param url JDBC URL
* @param props Properties to modify
* @param classLoader Class loader context
*/
public void setDefaultConnectionProps(String url, Properties props, ClassLoader classLoader);
}Usage Example:
// Automatic usage via Flyway
Flyway flyway = Flyway.configure()
.dataSource("jdbc:mariadb://localhost:3306/mydb", "user", "password")
.load(); // MariaDBDatabaseType automatically discovered and used
// Direct usage (advanced)
MariaDBDatabaseType dbType = new MariaDBDatabaseType();
boolean canHandle = dbType.handlesJDBCUrl("jdbc:mariadb://localhost:3306/test");
int priority = dbType.getPriority(); // Returns 1 (higher than MySQL)jdbc:mysql://host:port/database - Standard MySQLjdbc:google://project:region:instance/database - Google Cloud SQLjdbc:p6spy:mysql://host:port/database - P6Spy proxyjdbc:aws-wrapper:mysql://host:port/database - AWS wrapper URLsjdbc:mariadb://host:port/database - Standard MariaDBjdbc:p6spy:mariadb://host:port/database - P6Spy proxycom.mysql.cj.jdbc.Driver - Modern MySQL Connector/Jcom.mysql.jdbc.GoogleDriver - Google Cloud SQLsoftware.amazon.jdbc.Driver - AWS wrappercom.p6spy.engine.spy.P6SpyDriver - P6Spy proxycom.mysql.jdbc.Driver - Legacy MySQL driverorg.mariadb.jdbc.Driver - MariaDB driver (if not disabled)org.mariadb.jdbc.Driver - Standard MariaDB drivercom.p6spy.engine.spy.P6SpyDriver - P6Spy proxySELECT VERSION() contains "MariaDB" (Azure Database for MariaDB)Both database types set the following default connection properties:
props.put("connectionAttributes", "program_name:" + APPLICATION_NAME);This helps identify Flyway connections in database logs and monitoring systems.
Install with Tessl CLI
npx tessl i tessl/maven-org-flywaydb--flyway-mysql