5

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.

NewUser
  • 12,713
  • 39
  • 142
  • 236
  • 1
    possible duplicate of [Quick easy way to migrate SQLite3 to MySQL?](http://stackoverflow.com/questions/18671/quick-easy-way-to-migrate-sqlite3-to-mysql) – p.campbell Jul 15 '11 at 17:10

5 Answers5

4
  1. assuming your sqlite db file is login.db
  2. download this script as sqlite3-to-mysql.sh
  3. 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
  4. import to mysql: mysql -uuser -ppassword -D database < mysql.sql
xialu
  • 174
  • 3
  • 11
0

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:

  1. Create your database
  2. (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.
  3. File > Import
  4. Format: CSV
  5. Check: "First line contains field names"
  6. 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
Oliver P
  • 3,029
  • 2
  • 16
  • 12
-3

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.

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
ketan
  • 390
  • 3
  • 6
-3

To directly import it to the database in just one command:

sqlite3 database.db .dump | mysql -uuser -ppassword database
Nils Werner
  • 34,832
  • 7
  • 76
  • 98
-23

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.

Peon the Great
  • 1,289
  • 1
  • 10
  • 17