views:

831

answers:

4

I currently have a relatively small (4 or 5 tables, 5000 rows) MySQL database that I would like to convert to an sqlite database. As I'd potentially have to do this more than once, I'd be grateful if anyone could recommend any useful tools, or at least any easily-replicated method.

(I have complete admin access to the database/machines involved.)

A: 

If it's just a few tables you could probably script this in your preferred scripting langauge and have it all done by the time it'd take to read all the replies or track down a suitable tool. I would any way. :)

Kev
+2  A: 

As long as a MySQL dump file doesn't exceed the SQLite query language, you should be able to migrate fairly easily:

 tgl@moto~$ mysqldump old-database > old-database-dump.sql
 tgl@moto~$ sqlite3 -init old-database-dump.sql new-database

I haven't tried this myself.

UPDATE:

Looks like you'll need to do a couple edits of the MySQL dump. I'd use sed, or Google for it.

Just the comment syntax, auto_increment & TYPE= declaration, and escape characters differ.

Terry Lorber
A: 

@ Terry Lorber

The problem is that the MySQL dialect is different to the SQLite one. Otherwise, a straight dump would have been easy. ;o)

ChrisThomas123
+2  A: 

I've had to do similar things a few times. The easiest approach for me has been to write a script that pulls from one data source and produces an output for the new data source. Just do a SELECT * query for each table in your current database, and then dump all the rows into an INSERT INTO query for your new database. You can either dump this into a file or pipe it straight into the database frontend.

It's not pretty, but honestly, pretty hardly seems to be a major concern for things like this. This technique is quick to write, and it works. Those are my primary criteria for things like this.

You might want to check out this thread, too. It looks like a couple of people have already put together basically what you need. I didn't look that far into it, though, so no guarantees.

Derek Park