简体   繁体   中英

How to import data to an in-memory database?

有没有办法将MS SQL,MySQL等数据库中的数据导入内存数据库,如HSQLDB,H2等?

H2 supports a special database URL that initialized the database from a SQL script file :

"jdbc:h2:mem;INIT=RUNSCRIPT FROM '~/create.sql'"

HSQLDB and Apache Derby don't support such a feature as far as I know.

In Hibernate: Adding import.sql to the class path works great, hbm2dll checks if the file exists and executes it. The only details is that every sql command most be on one row, otherwise it will fail to execute

I think you need to do

  1. query the data out from MS SQL

  2. import the data into in-memory DB with its API

Either SQL expressions or DB related APIs

Latest versions of HSQLDB allow you to open a CSV (comma separated values) or other delimiter separated data file as a TEXT TABLE in HSQLDB even with mem: databases, which can then be copied to other tables.

As others have pointed out, there are also capable and well maintained third party tools for this purpose.

You could dump the data as SQL INSERT statements then read it back.

You could read to a temporay object (like a struct) then write back to the internal db.

看看免费的“通用数据库转换器” http://eva-3-universal-database-converter-udc.optadat-com.qarchive.org/ - 它声称支持MySQL,MS-SQL和HSQLDB,其他。

It really depends on what ways you think about. Is there a tool that could do it automatically without programming? Maybe.

Do you want to develop it? Then find out whether your favorite language supports both database engines(standard and in memory) and if it does, just write a script that does it. Process everything in chunks(fetch n rows at a time then insert them; repeat). How big the chunk size? It's up to you, try different sizes(say 100, 500, 1k etc.) see which one performs better on your hardware, fine tune to the sweet spot.

If your favorite language on the other hand doesn't support both of them, try using something that does.

You can use dbunit for dumping the database to xml files and importing it back to another rdbms.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM