Friday, December 6, 2013

How to convert MySQL to SQLite



My projects needed SQLite file.
My database in MySQL has to be converted into SQLite.

So, searched into google and gone over threads of different forums,
finally, I was able to make SQLite.

links when I searched,
http://stackoverflow.com/a/9933603/1009225
http://stackoverflow.com/a/8779980/1009225

<code>
./mysql2sqlite.sh -u root --default-character-set=utf8 MySQL_db | sqlite3 SQLite_db.sqlite
#learned from http://stackoverflow.com/a/9933603/1009225
</code>

As this code needs,
1.mysql2sqlite.sh from GitHub
https://gist.github.com/esperlu/943776#file-mysql2sqlite-sh
Copy
mysql2sqlite.sh to C:\cygwin\bin

2.In cygwin, Copy
mysqldump.exe from C:\xampp\mysql\bin to C:\cygwin\bin

3.sqlite3 downloaded from
http://www.sqlite.org/download.html
sqlite-shell-win32-x86-3080100.zip(use according to your OS)
and copy
sqlite3.exe to C:\cygwin\bin

4.Start Apache and MySQL Services from Xampp C:\xampp\xampp-control.exe

5.Run mintty/cygwin/bash
run this command to make file executable learned from http://stackoverflow.com/a/8779980/1009225
<code>
chmod +x mysql2sqlite.sh
</code>

and the final command to convert MySQL to SQLite
<code>
./mysql2sqlite.sh -u root --default-character-set=utf8 MySQL_db | sqlite3 SQLite_db.sqlite
</code>

// -u root ===> your localhost
//--default-character-set=utf8 ===> to make unicode
//MySQL_db ===> MySQL Database name(db from phpMyAdmin)
//SQLite_db.sqlite ===> SQLite database which is saved into the same directory C:\users\user(see by pwd for address)

this should convert your MySQL database to SQLite in you C:\Users\user directory.
or pwd for the path.

Thank you for your visit.

No comments:

Post a Comment