Converting a MySQL database to SQLite on a Mac
I recently decided to migrate an e-commerce shopping cart system I have been developing for a long time from MySQL to SQLite. I went back and forth over this idea, but I decided it made sense to have an e-commerce shopping cart that the user can install by literally dropping the folder into the site.
In order to make the transition as easy as possible, I decided to try to convert the database rather than re-create the many tables and fields needed to make it all work. During my research I found some paid products and a bunch of scripts scattered around, many in Perl. I was looking for something simple that I could try out with minimal effort.
I found a script posted at http://www.jbip.net/content/how-convert-mysql-sqlite that worked like a charm for me. I use a Macbook Pro running Snow Leopard. I develop using a local MySQL database and Apache using MAMP.
In order to get started, you need to do a MySQL dump of your database (in the correct format). I tried using Navicat to do the dump and it didn’t work. So, I dug around and discovered that from the terminal you can go to /Applications/MAMP/Library/bin/ and run the following command
mysqldump -u root -p –compatible=ansi –skip-opt dbname > dumpfile
This created a file called dumpfile which I then moved into a temp folder on my desktop. From there, I pasted the script from JBipNet into my editor and saved it as mysql-to-sqlite.sh into the temp folder.
Finally, I went into the terminal again and set the permissions on the script and ran it:
- cd /Users/myname/Desktop/temp
- chmod +x mysql-to-sqlite.sh
- ./mysql-to-sqlite.sh dumpfile
This worked like a charm for me and my database was quickly converted to a valid SQLite 3 database. I then opened the database up using my favorite free SQLite 3 database management tool (a free FireFox plugin).
Nicely explained. It worked perfectly. Thank's for the tip ! And beautiful website btw.
ReplyDelete