/mysql2h2-converter

A MySQL to H2 SQL conversion library written in Java

Primary LanguageJavaMIT LicenseMIT

mysql2h2-converter

A MySQL to H2 SQL conversion library written in Java.

Parse a MySQL dump and convert it to H2 statements either as an embedded library or as a standalone tool.

Next steps can include:

Other ideas:

Usage

As a library:

private static void convertAndCreate(Statement stmt, String sqlDump) throws SQLException, ParseException {
    Iterator<SqlStatement> sourceIterator = SQLParserManager.parseScript(new StringReader(sqlDump));
    Iterator<SqlStatement> converted = H2Converter.convertScript(sourceIterator);
    while (converted.hasNext()) {
        stmt.execute(converted.next().toString());
    }
}

On the command line, after mvn package of course:

$ java -jar target/mysql2h2-converter-tool-0.3.0.jar demos/disconf-mysql.sql > disconf-h2.sql

Building

mvn clean package will generate the SQL parser and build an executable JAR.

enhance branch

Extend the parser to support more statements, see BasicTest and ConverterTest diff for details.

Since last commit of andrewparmet/mysql2h2-converter is 2018, change this library's pom to a new group and new version, and you can use the new one from JitPack.

Gradle example:

Step 1. Add the JitPack repository to your build file:

allprojects {
    repositories {
        ...
        maven { url 'https://jitpack.io' }
    }
}

Step 2. Add the dependency:

dependencies {
    implementation 'com.github.alphahinex:mysql2h2-converter:0.3.0'
}

License

This code is provided under the MIT license.