简体   繁体   中英

mysql dump into derby

I'm using derby for development in eclipse. Is it possible to dump a table from MySQL and use it for derby in some way? I know that ddl & dml are different for both dbms but I'm looking for a way, other than dump/export, that would be appropriate.

There are two options I can find; if I understand your question correctly, I think at least one will cover what you are looking for.

If your focus is the data (or a subset thereof) from a single table, use ij as indicated in the Derby tools documentation (see "Using the bulk import and export procedures"). The data can be extracted from MySQL using intrinsic formatting commands in the required format, which appears to be pretty standard CSV (this would require that you have an appropriate table already existing in your Derby database).

Here's an example from the MySQL forums:

SELECT a,b,a+b INTO OUTFILE '/tmp/result.text'
FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY '\n'
FROM test_table; 

If you want to import everything, Apache DdlUtils will allow the transfer of an entire schema from MySQL to Derby. This would not require the repeated table definition in Derby, as it would come across as part of the import/export process with DdlUtils.

Unless you need to automate the process, the " DBCopy Plugin for SQuirreL SQL Client " tool might work for you. There are probably other tools, but that's the one I know (however never used myself).

If you do need to automate the process, and if you don't care so much about the DDL, then I would probably use CSV.

To take over the data from MySQL (production environment) to Derby (development environment), I use following command:

mysqldump -u root -h 127.0.0.1 --compatible=ansi --complete-insert --skip-add-drop-table --skip-add-locks --skip-comments --skip-disable-keys --skip-set-charset --no-create-info dbname > export.sql

But specially in Derby, I have also the problem of disalbing constraints. Therefore, the insert statements have to be in the correct order!

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