Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert MySQL script to H2

Tags:

I have an init script for my MySQL database but for test purposes I wan't to use a H2 database. Anyone knows how to convert the file or at least has a list of the syntax differences ? thanks.

like image 809
user1502150 Avatar asked Jul 23 '12 10:07

user1502150


People also ask

Does H2 support MySQL?

SQL SupportCompatibility modes for IBM DB2, Apache Derby, HSQLDB, MS SQL Server, MySQL, Oracle, and PostgreSQL.

What is the difference between H2 and MySQL?

MySQL is a server - based database - it runs as a separate process from your application, and is commonly used in production deployments. H2 is a lightweight database, which can run entirely in-memory, or with disk storage, either in your application's process (embedded) or in a separate process.

Is H2 and SQL same?

H2 Database and Microsoft SQL Server belong to "Databases" category of the tech stack. According to the StackShare community, Microsoft SQL Server has a broader approval, being mentioned in 697 company stacks & 2723 developers stacks; compared to H2 Database, which is listed in 9 company stacks and 19 developer stacks.


2 Answers

Here is a good instruction by Matthew Casperson

Exporting from MySQL to H2

Here is a short list of steps, to convert from mysql to h2:

Fix up single quotes

CREATE TABLE `user` ( `name` varchar(20) NOT NULL,
convert to
CREATE TABLE user ( name varchar(20) NOT NULL,

Fix up hex numbers
Fix up bits
Don't include ranges in keys
Remove character sets (remove CHARACTER SET ...)
Remove COLLATE settings (f.e. COLLATE utf8_unicode_ci)
Remove indexes on BLOBS, CLOBS and TEXT fields
Make all index names unique
Use the MySQL compatibility mode (jdbc:h2:~/test;MODE=MySQL)

like image 98
Vitali Heinrich Avatar answered Nov 15 '22 13:11

Vitali Heinrich


There are a number of database tools that help migrating data from one to another database, for example:

  • Flyway
  • SQuirreL DB Copy Plugin
like image 27
Thomas Mueller Avatar answered Nov 15 '22 13:11

Thomas Mueller