Is it possible to convert from MySQL to SQLite with a free tool on windows?
15 Answers
There is a mysql2sqlite.sh script on GitHub
As described in the header, the script can be used like this:
./mysql2sqlite.sh myDbase | sqlite3 database.sqlite
alternatives
- an updated version https://github.com/dumblob/mysql2sqlite
- A simpler script was posted at the the MySQL Forums

- 31,011
- 31
- 115
- 189
-
13Works as charm! Here is a bit of documentation: `$ ./mysql2sqlite.sh -h host -u MyUserName -pMySecretPassWord myDbase | sqlite3 database.sqlite` https://gist.github.com/943776 – kachar Oct 30 '12 at 12:58
-
1The script just pulls arguments from the command line and passes them to mysqldump, so you can find out about configuring custom ports, etc with `man mysql` or `man mysqldump` – Devin Howard Oct 27 '15 at 04:47
-
3It's worth noting that this script has been superseded by a successor maintained here: https://github.com/dumblob/mysql2sqlite – drzax Jul 20 '16 at 08:10
-
Even better to play with non-ascii characters: $./mysql2sqlite.sh --default-character-set=utf8 -hHost -uUser -pPass db | sqlite3 db.sqlite https://gist.github.com/esperlu/943776#gistcomment-984448 – Sun Junwen Aug 06 '19 at 04:43
-
1Worked for me using `$./mysql2sqlite.sh -u MyUserName -p MyPassword --column-statistics=0 --default-character-set=utf8 MyDatabase | sqlite3 database.sqlite` – Imjohsep Jan 28 '21 at 17:52
-
When I try to execute the script it says "Permission denied". `sudo`doesn't work either. – theerrormagnet Apr 25 '21 at 08:06
-
For anyone looking for a solution for Django, you should use its built in dumpdata and loaddata command, please see: https://stackoverflow.com/questions/3034910/whats-the-best-way-to-migrate-a-django-db-from-sqlite-to-mysql – martintrapp May 14 '22 at 15:01
Here is a list of converters. (snapshot at archive.today)
An alternative method that would work even on windows but is rarely mentioned is: use an ORM class that abstracts specific database differences away for you. e.g. you get these in PHP (RedBean), Python (Django's ORM layer, Storm, SqlAlchemy), Ruby on Rails (ActiveRecord), Cocoa (CoreData) etc.
i.e. you could do this:
- Load data from source database using the ORM class.
- Store data in memory or serialize to disk.
- Store data into destination database using the ORM class.

- 103
- 1
- 6

- 7,481
- 4
- 58
- 67
Sequel (Ruby ORM) has a command line tool for dealing with databases, you must have ruby installed, then:
$ gem install sequel mysql2 sqlite3
$ sequel mysql2://user:password@host/database -C sqlite://db.sqlite

- 2,214
- 2
- 22
- 40
-
3
-
2and `gem install pg` if you want to convert from or to a postgres db, sequel should have adapters for major db's – Macario Feb 27 '14 at 19:16
-
4
-
1Note: You'll need the `ruby-dev` package to build these native gem packages. – Panda Jul 16 '14 at 07:49
-
1Had to use "gem install sequel mysql2 sqlite3" and then "sequel mysql2://user:password@host/database -C sqlite://db.sqlite" PERFECT – unom Aug 11 '14 at 18:24
-
I then dug up my ruby skills and tried the answer below this one, but had to use mysql2 instead of mysql and this, "gem install sequel mysql2 sqlite3" then "sequel mysql2://user:password@host/database -C sqlite://db.sqlite" finally produced some meaningful errors. Seems I had some illegal dates in some fields, like 0004-00-00 and I had to correct those. Installed Firefox with the SQLite Manager add-on and went in and edited about 10 fields that had this problem. Reran the command and DONE! Finally. – unom Aug 12 '14 at 09:42
-
-
-
You may need to quote the arguments if your password has shell-unsafe characters, such as a semi-colon. – kainjow Apr 09 '15 at 17:08
-
mysql - `Error: Sequel::DatabaseError: SQLite3::SQLException: unrecognized token: "'"` mysql2 - `Error: Sequel::DatabaseError: SQLite3::SQLException: unrecognized token: "'����"` – tread Jun 15 '15 at 08:36
-
-
@teawithfruit I am not sure, you can ask Jeremy Evans (https://github.com/jeremyevans), the maintainer of sequel ORM. I've heard he is very committed to the project and to help others with any issues related to it. There is an IRC channel too. http://sequel.jeremyevans.net/development.html – Macario Sep 18 '15 at 01:47
-
I've built a docker container for the sequel one liner database conversion https://blog.chib.me/how-to-convert-databases-with-one-line-of-code/ – web-chib Feb 07 '16 at 13:06
-
Note: You will need `libsqlite3-dev` package to install `sqlite3` gem – Tushar Goswami Feb 13 '16 at 07:35
-
Note: You will need `libmysqlclient-dev` package to install `mysql2` gem (tested on Ubuntu 20.04 LTS). Possibly `ruby-dev` might be needed too (I had this installed already). – Jan Święcki Aug 16 '21 at 19:29
I faced the same problem about 2 days ago when I had to convert a 20GB+ MySQL database to SQLite. It was by no means an easy task and I ended up writing this Python package that does the job.
The upside of it being written in Python is that it's cross platform (unlike a shell/bash script) and can all be easily installed using pip install
(even on Windows). It uses generators and chunking of the data being processed and is therefore very memory efficient.
I also put in some effort to correctly translate most of the datatypes from MySQL to SQLite.
The tool is also thoroughly tested and works on Python 2.7 and 3.5+.
It is invokable via command line but can also be used as a standard Python class which you can include in some larger Python orchestration.
Here's how you use it:
Usage: mysql2sqlite [OPTIONS]
Options:
-f, --sqlite-file PATH SQLite3 database file [required]
-d, --mysql-database TEXT MySQL database name [required]
-u, --mysql-user TEXT MySQL user [required]
-p, --mysql-password TEXT MySQL password
-h, --mysql-host TEXT MySQL host. Defaults to localhost.
-P, --mysql-port INTEGER MySQL port. Defaults to 3306.
-c, --chunk INTEGER Chunk reading/writing SQL records
-l, --log-file PATH Log file
-V, --vacuum Use the VACUUM command to rebuild the SQLite
database file, repacking it into a minimal amount
of disk space
--use-buffered-cursors Use MySQLCursorBuffered for reading the MySQL
database. This can be useful in situations where
multiple queries, with small result sets, need to
be combined or computed with each other.
--help Show this message and exit.

- 9,261
- 4
- 31
- 28
-
2Hey @techouse, this looks great! Is there any way it could work with a `.sql` dump file or does it require connection to an installed MySQL database? – vortek Apr 14 '19 at 22:44
-
Hey! Ummm, no this *requires* a working MySQL database. If you have a dump without an actual server your best bet is to change the file manually *if* you know what you're doing. – Klemen Tusar Apr 15 '19 at 11:02
-
@arkadianriver I suggest you always use virtual environments with Python – Klemen Tusar May 09 '19 at 07:13
-
This tool was pretty awesome; great job. I exported this to a .sql dump file by running `sqlite3 db.sql`, then executed the following commands to have sqlite generate the dump file: `.output init.sql` `.dump` `.exit` -- I will note the only unfortunate thing so far is that views weren't exported correctly, but that's not a huge deal. – Josh Green Oct 01 '20 at 17:40
-
Follow up to my above comment: it also appears that the defaulted values for columns are not exported. – Josh Green Oct 01 '20 at 21:02
-
What encoding do you use? Opening the file with utf-8 results in SQLite format 3 @ G � 9 G .4 � �����.��p&��*" g=�indexfrench_index_French_typefrenchCREATE INDEX "french_index_French_type" ON "french" ("type")pC�indexfrench_index_French_articlefrenchCREATE INDEX "french_index_French_article" ON "french" ("article")�/ �9tablefrenchfrenchCREATE TABLE "french" ( "id" INTEGER NOT NULL , //stuff )mA�... – Sarah Multitasker Aug 02 '21 at 07:46
-
@SarahMultitasker SQLite uses utf8 by default. What Python are you on. Also, please take this to GitHub issues for better traction and quicker resolution – Klemen Tusar Aug 02 '21 at 07:51
Not every DB schema can be converted. MySQL is more complex and feature-rich than SQLite. However, if your schema is simple enough, you could dump it into an SQL file and try to import it / load it into an SQLite DB.

- 73,079
- 34
- 148
- 203
-
1After dumping your MySQL database to a file, you can use this script to convert it to SQLite https://github.com/dumblob/mysql2sqlite (as mentioned in @David_LeBauer 's answer). – Paul Rougieux Jan 22 '20 at 13:34
Simplest way to Convert MySql DB to Sqlite:
1) Generate sql dump file for you MySql database.
2) Upload the file to RebaseData online converter here
3) A download button will appear on page to download database in Sqlite format

- 929
- 1
- 14
- 36
I found the perfect solution
First, you need this script (put it into a file called 'mysql-to-sqlite.sh'):
#!/bin/bash
if [ "x$1" == "x" ]; then
echo "Usage: $0 <dumpname>"
exit
fi
cat $1 |
grep -v ' KEY "' |
grep -v ' UNIQUE KEY "' |
grep -v ' PRIMARY KEY ' |
sed '/^SET/d' |
sed 's/ unsigned / /g' |
sed 's/ auto_increment/ primary key autoincrement/g' |
sed 's/ smallint([0-9]*) / integer /g' |
sed 's/ tinyint([0-9]*) / integer /g' |
sed 's/ int([0-9]*) / integer /g' |
sed 's/ character set [^ ]* / /g' |
sed 's/ enum([^)]*) / varchar(255) /g' |
sed 's/ on update [^,]*//g' |
sed 's/\\r\\n/\\n/g' |
sed 's/\\"/"/g' |
perl -e 'local $/;$_=<>;s/,\n\)/\n\)/gs;print "begin;\n";print;print "commit;\n"' |
perl -pe '
if (/^(INSERT.+?)\(/) {
$a=$1;
s/\\'\''/'\'\''/g;
s/\\n/\n/g;
s/\),\(/\);\n$a\(/g;
}
' > $1.sql
cat $1.sql | sqlite3 $1.db > $1.err
ERRORS=`cat $1.err | wc -l`
if [ $ERRORS == 0 ]; then
echo "Conversion completed without error. Output file: $1.db"
rm $1.sql
rm $1.err
else
echo "There were errors during conversion. Please review $1.err and $1.sql for details."
fi
Then, dump a copy of your database:
you@prompt:~$ mysqldump -u root -p --compatible=ansi --skip-opt generator > dumpfile
And now, run the conversion:
you@prompt:~$ mysql-to-sqlite.sh dumpfile
And if all goes well, you should now have a dumpfile.db which can be used via sqlite3.
you@prompt:~$ sqlite3 dumpfile.db
SQLite version 3.6.10
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
dg_cities dg_forms dg_surnames
dg_counties dg_provinces dg_user_accounts
dg_countries dg_provinces_netherlands
dg_first_names dg_states

- 2,294
- 3
- 18
- 25

- 331
- 3
- 10
There are different ways to do this. I also had this problem and I searched a lot and then I got a simple way to convert MySQL to SQLite.
Follow these steps:
First You Need to Install SQLite DB Browser (very small and fast to view Tables and Data)
Open your MySQL File in Notepad or it would be great if you open in Notepad++
Remove First extra Lines Contains Information or Queries and Save it.
Open SQLite DB Browser, Create Database, then Tables, and Same Types as it is in MySQL Database.
In Menu Bar of SQLite DB Browser Select File-> then Import data MySQL File which you saved.
It will easily Convert into SQLite After Warning Dialog.
If error then remove more extra lines if your MySQL file have.
You can also Install MySQL to SQLite Converter Software on trial Basis, but the information I am giving for conversion is life time.

- 6,405
- 6
- 28
- 69

- 156
- 1
- 11
-
This worked fine if your data have no character like apostrophe. For example "This is Peter's book" in sql dumb will be 'This is Peter\'s book'. This will make DB Browser throw error, for a large data it is difficult to remove. But if you import the data from phpAdmin as CSV to DB Browser, that import will be successful. I hope this help – Seunope Dec 19 '17 at 09:53
-
2But what "extra lines" though ? You could have incompatible data types all over the file. – elig Mar 22 '21 at 02:56
I tried a number of methods on this thread, but nothing worked for me. So here is a new solution, which I also found to be very simple:
- Install RazorSQL. Works for Mac, Windows and Linux.
- In RazorSQL connect to your database, on localhost for example. Conversion doesn't work with sql dump files.
- Right click on your database -> Database Conversion -> select SQLite.
This will save a txt file with all the
sqlite
queries necessary to create this database. - Install a SQLite database manager, like DB Browser for SQLite. It works on any OS.
- Create an empty database, go to Execute SQL tab and paste the content from step 3.
That's it, now you have your SQLite database.

- 469
- 3
- 15
-
RazorSQL seems to just build a "common" *.sql file with table definitions and data insert intos but nothing particularly SQLite specific. It did not export Views which is a big minus. The mysqldump client which comes with MySql exports views too but it also produces lot of conditional stuff etc. what SQLite will not digest. – dalilander Feb 13 '18 at 14:39
My solution to this issue running a Mac was to
- Install Ruby and sequel similar to Macario's answer. I followed this link to help setup Ruby, mysql and sqlite3 Ruby on Rails development setup for Mac OSX
Install sequel
$ gem install sequel
If still required
% gem install mysql sqlite3
then used the following based of the Sequel doc bin_sequel.rdoc (see Copy Database)
sequel -C mysql://myUserName:myPassword@host/databaseName sqlite://myConvertedDatabaseName.sqlite
A windows user could install Ruby and Sequel for a windows solution.

- 79
- 3
-
How can I copy only one table from the DB not entire mysql database ? – vaibhavatul47 Apr 10 '16 at 19:21
-
For a single table in the past I have done this, but there may be a better way. Export the table as csv with the column names in the first row option ticked. Then using DB Browser for SQLite, import the table into my existing sqlite database using the import table from csv option. You will then likely have to go in and change the fields to the type you require as I believe all the fields will be set to TEXT. In the project I was working on though we developed a process were we made an api call to return all the data in a table and then inserted/replaced the data in the apps database. – Grant Luck Apr 11 '16 at 23:18
-
It seems to be working. Nonetheless, I cannot find where is the output file. Can you help me? – Pontios Nov 02 '18 at 16:51
I like the SQLite2009 Pro Enterprise Manager suggested by Jfly. However:
The MySQL datatype INT is not converted to SQlite datatype INTEGER (works with DBeaver )
It does not import foreign key constaints from MySQL (I could not find any tool that supports the transfer of foreign key constraints from MySQL to SQlite.)

- 10,010
- 7
- 61
- 117
From list of converter tools I found Kexi. It is a UI tool to import from various DB servers (including MySQL) into SQLite. When importing some database (say from MySQL) it stores it in Kexi format. The Kexi format is the 'native' SQLite format. So simply copy the kexi file and have your data in sqlite format

- 753
- 1
- 8
- 19
-
2023 : this is the best solution, just install `sudo apt install kexi` then install the driver `sudo apt install kexi-mysql-driver` (and even postgresql), and open it, and bring it from the server, open it as a file in SQLite (and remove the extra tables created by Kexi) – Abdelouahab Jan 29 '23 at 10:55
If you have experience write simple scripts by Perl\Python\etc, and convert MySQL to SQLite. Read data from Mysql and write it on SQLite.

- 87,898
- 29
- 167
- 228

- 1,690
- 3
- 16
- 30
If you have been given a database file and have not installed the correct server (either SQLite or MySQL), try this tool: https://dbconvert.com/sqlite/mysql/ The trial version allows converting the first 50 records of each table, the rest of the data is watermarked. This is a Windows program, and can either dump into a running database server, or can dump output to a .sql file

- 3,142
- 1
- 24
- 24