<p>I currently have a relatively small (4 or 5 tables, 5000 rows) MySQL database that I would like to convert to an sqlite database.  As I'd potentially have to do this more than once, I'd be grateful if anyone could recommend any useful tools, or at least any easily-replicated method.</p>

<p>(I have complete admin access to the database/machines involved.)</p>

[{'answer_id': 7216, 'author': 'Kev', 'author_id': 419, 'author_profile': 'https://Stackoverflow.com/users/419', 'pm_score': 1, 'selected': False, 'text': "<p>If it's just a few tables you could probably script this in your preferred scripting langauge and have it all done by the time it'd take to read all the replies or track down a suitable tool. I would any way. :)</p>\n"}, {'answer_id': 7218, 'author': 'Terry G Lorber', 'author_id': 809, 'author_profile': 'https://Stackoverflow.com/users/809', 'pm_score': 2, 'selected': False, 'text': '<p>As long as a MySQL dump file doesn\'t exceed the <a href="http://www.sqlite.org/lang.html" rel="nofollow noreferrer">SQLite</a> query language, you should be able to migrate fairly easily:</p>\n\n<pre><code> tgl@moto~$ mysqldump old-database &gt; old-database-dump.sql\n tgl@moto~$ sqlite3 -init old-database-dump.sql new-database\n</code></pre>\n\n<p>I haven\'t tried this myself.</p>\n\n<p><em>UPDATE:</em></p>\n\n<p>Looks like you\'ll need to do a couple edits of the MySQL dump.  I\'d use sed, or <a href="http://www.perlmonks.org/index.pl?node_id=150476" rel="nofollow noreferrer">Google for it.</a></p>\n\n<p>Just the comment syntax, auto_increment &amp; TYPE= declaration, and escape characters differ.</p>\n'}, {'answer_id': 7298, 'author': 'Derek Park', 'author_id': 872, 'author_profile': 'https://Stackoverflow.com/users/872', 'pm_score': 3, 'selected': False, 'text': '<p>I\'ve had to do similar things a few times.  The easiest approach for me has been to write a script that pulls from one data source and produces an output for the new data source.  Just do a <code>SELECT *</code> query for each table in your current database, and then dump all the rows into an <code>INSERT INTO</code> query for your new database.  You can either dump this into a file or pipe it straight into the database frontend.</p>\n\n<p>It\'s not pretty, but honestly, pretty hardly seems to be a major concern for things like this.  This technique is quick to write, and it works.  Those are my primary criteria for things like this.</p>\n\n<p>You might want to check out <a href="http://www.perlmonks.org/index.pl?node_id=150476" rel="noreferrer">this thread</a>, too.  It looks like a couple of people have already put together basically what you need.  I didn\'t look that far into it, though, so no guarantees.</p>\n'}, {'answer_id': 6000364, 'author': 'David d C e Freitas', 'author_id': 40961, 'author_profile': 'https://Stackoverflow.com/users/40961', 'pm_score': 2, 'selected': False, 'text': '<p>Here is a list of converters:</p>\n\n<ul>\n<li><a href="http://www.sqlite.org/cvstrac/wiki?p=ConverterTools" rel="nofollow">http://www.sqlite.org/cvstrac/wiki?p=ConverterTools</a></li>\n</ul>\n\n<p><hr/>\nAn alternative method that would work nicely but is rarely mentioned is: use a ORM class that abstracts the specific database differences away for you.  e.g. you get these in PHP (<a href="http://www.redbeanphp.com" rel="nofollow">RedBean</a>), Python (Django\'s ORM layer, <a href="https://storm.canonical.com/" rel="nofollow">Storm</a>, <a href="http://www.sqlalchemy.org" rel="nofollow">SqlAlchemy</a>), Ruby on Rails (<a href="http://ar.rubyonrails.org/" rel="nofollow"> ActiveRecord</a>), Cocoa (<a href="http://developer.apple.com/technologies/mac/data-management.html" rel="nofollow">CoreData</a>)</p>\n\n<p>i.e. you could do this:</p>\n\n<ol>\n<li>Load data from source database using the ORM class.</li>\n<li>Store data in memory or serialize to disk.</li>\n<li>Store data into source database using the ORM class.</li>\n</ol>\n'}]
['https://Stackoverflow.com/questions/7211', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/916/']