Convert MySQL script to H2

好久不见. 提交于 2019-11-29 05:54:32

问题


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.


回答1:


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

  • Flyway
  • SQuirreL DB Copy Plugin



回答2:


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)




回答3:


Use this java tool, It so easy to use just download and run the jar file. It has both a GUI and can also be intergrated within your code if need be. MysqlDumpToH2




回答4:


I saw this on the iConomy FAQ (http://ico.nexua.org/Main/FAQ#toc28):

How do I convert H2 to MySQL?

Since they are both SQL based all you need to do is Export the h2 sql data into a .sql file, and import it into a MySQL database using a GUI, or PHPMyAdmin, Admininer, SQLBuddy, Etc.. To do this, you can either use the h2 built in console or RazorSQL h2 GUI (Multi-platform). If you want the SQL output of the database, the full path to your minecraft.h2.db without the .h2.db part

Use the following line inside a .sh / .bat file or console inside the /lib folder where h2.jar is located:

java -cp h2*.jar org.h2.tools.Script -url jdbc:h2:path/to/minecraft -user sa -password sa

This will output a file named backup.sql and will contain the raw SQL output of the database. You may need to edit it a bit so it matches up with MySQL. :)



来源:https://stackoverflow.com/questions/11610850/convert-mysql-script-to-h2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!