We can export the structure and data of an existing MySQL database by creating a series of SQL commands in a file and using the target system, in this case SQLite, to run the commands in a text file. Do the following:
Open the database in PHPMyAdmin.
Click the Export tab
Export Section (on left) - Select SQL
Options Section (on right)
SQL compatibility mode: choose ANSI
Structure Section
Uncheck all but "Add IF NOT EXISTS"
(Data Section - If you only want to export the database structure, uncheck this. If you want to export both the structure and the data, check this.)
Click Go. A file called databasename.sql will be created and downloaded to your Downloads folder.
Because there are slight differences in the CREATE TABLE command between MySQL and SQLite, we'll have to fix the commands somewhat:
Open the file and make the following find and replace substitutions:
Replace the phrase "int(N) NOT NULL auto_increment" with "primary key autoincrement"
For each table, delete the line that reads "PRIMARY KEY (column name here), including the preceding comma.
Compare the following sample SQL statements:
Open a terminal window.
At prompt, type:
sqlite3 /path/to/database/databasename.sqlite
For example:
sqlite3 /Users/devin/Desktop/acmeco.sqlite
This will open the sqlite command line program and simultaneously open the database file. If the database file doesn't exist, it will create it.
At prompt, type:
.read /path/to/database/exportfilename.sql
Note errors, if any, and modify source .sql file to eliminate errors.
When done with sqlite, type Control+D to exit.
This procedure will create the database structure. You would then insert the data exactly as we did earlier with the MySQL databases.