I have a .sqlite file which I want to convert into mysql. So is there any way to convert it into mysql?I am using ubuntu. So is there any shell script to change it. Any help will be highly appreciable.
5 Answers
- assuming your sqlite db file is
login.db
- download this script as
sqlite3-to-mysql.sh
- this command will tranform your sqlite db file to standard mysql sql file:
sqlite3 login.db .dump > sqlite.sql && bash sqlite3-to-mysql.sh sqlite.sql > mysql.sql && rm sqlite.sql
- import to mysql:
mysql -uuser -ppassword -D database < mysql.sql

- 174
- 3
- 11
I've tried this recently and most answers don't work because they're out of date. e.g. python vs python3
A method that worked for me that should never go out of date is to export the tables to CSV and then import them as CSV. I used Sequel Pro which can import a CSV. The downside is that you need to do each table individually. The upside is that this is a very robust method and doesn't require any custom scripts.
Run the following in your database folder changing "thedatabase" and the two occurances of "thetable" to the database name and table name respectively:
sqlite3 -header -csv thedatabase.db "select * from thetable;" > thetable.csv
For Sequel Pro:
- Create your database
- (Optional: Create table structure. Recommended to have the correct column types) You could get the create statement from an sqlite dump and fix them for mysql.
- File > Import
- Format: CSV
- Check: "First line contains field names"
- Check the field mappings and import
Explanation of the command to export:
- "sqlite3" is the command line client for sqlite databases.
- "-header -csv " sets the output to csv
- "thedatabase.db" is the database file
- "select * from thetable;" is the query to select all data from the table
- " > thetable.csv" redirects the output of the data to thetable.csv file

- 3,029
- 2
- 16
- 12
1) Export sqlite database to sql file
sqlite3 sqlite.db .dump > mysql.sql
2) Import mysql.sql file to mysql database using phpmyadmin or other tools.

- 124,992
- 159
- 614
- 958

- 390
- 3
- 6
To directly import it to the database in just one command:
sqlite3 database.db .dump | mysql -uuser -ppassword database

- 34,832
- 7
- 76
- 98
-
I guess you should delete the whitespace after `-p`. At least on my machine it works without withespace but not with a space between `-p` and my password. – Martin Thoma Jun 09 '13 at 12:29
-
-
Google "sqlite to mysql" will give you a lot of articles doing that ...
Okay, easiest is to open the .sqlite file using sqlite, .dump to a file, and the file is a text file containing SQL statements.
You shall be able to edit that file and run in your mysql DB thereafter.

- 1,289
- 1
- 10
- 17