documentation/Reference/Database Driver Reference/MySQL.md
{% include database-boilerplate.html %}
| - | MySQL | MariaDB |
|---|---|---|
| URL format | jdbc:mysql://host:port/database | jdbc:mysql://host:port/database |
| SSL support | Yes - add ?useSsl=true | Yes - add ?useSsl=true |
| Ships with Flyway Command-line | No | |
| Connector/J Download | Yes | |
| Maven Central coordinates | mysql:mysql-connector-java | org.mariadb.jdbc:mariadb-java-client |
| Supported versions | 5.1.44 and later | 2.0.0 and later |
| Default Java class | com.mysql.jdbc.Driver | org.mariadb.jdbc.Driver |
disableMariaDbDriver to your database URL.permitMysqlScheme=true to your database URL.MySQL support is a separate dependency for Flyway and will need to be added to your Java project to access these features.
<dependency>
<groupId>com.redgate.flyway</groupId>
<artifactId>flyway-mysql</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-mysql</artifactId>
</dependency>
buildscript {
dependencies {
implementation "com.redgate.flyway:flyway-mysql"
}
}
buildscript {
dependencies {
implementation "org.flywaydb:flyway-mysql"
}
}
DELIMITER statement to change the statement delimiter/!.../;# Comment)/* Single line comment */
CREATE TABLE test_data (
value VARCHAR(25) NOT NULL,
PRIMARY KEY(value)
);
/*
Multi-line
comment
*/
-- MySQL procedure
DELIMITER //
CREATE PROCEDURE AddData()
BEGIN
# MySQL-style single line comment
INSERT INTO test_data (value) VALUES ('Hello');
END //
DELIMITER;
CALL AddData();
-- MySQL comments directives generated by mysqlsump
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
-- Placeholder
INSERT INTO ${tableName} (name) VALUES ('Mr. T');
Flyway supports the following MySQL authentication methods:
{% include teams.html %}
A username and password can be retrieved from MySQL option files for authentication, in which case they do not need to be supplied in configuration. The following table lists which option files are searched for per operating system, in order.
| Windows | Other |
|---|---|
%WINDIR%\my.ini, %WINDIR%\my.cnf | /etc/my.cnf |
C:\my.ini, C:\my.cnf | /etc/mysql/my.cnf |
%MYSQL_HOME%\my.ini, %MYSQL_HOME%\my.cnf | $MYSQL_HOME/my.cnf |
%APPDATA%\MySQL\.mylogin.cnf | ~/.my.cnf |
| N/A | ~/.mylogin.cnf |
You can read more about MySQL option files here.
user and password from option files