Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

111 lines (67 sloc) 3.834 kb
= mysql2sqlite.rb
== DESCRIPTION
A Ruby script to convert and export MySQL databases to Sqlite databases.
== USAGE
Can be executed by either passing the database connection values directly:
./mysql2sqlite.rb database_name database_user database_password
or by passing it the path to a YAML-based configuration file:
./mysql2sqlite.rb config.yaml
== OUTPUT
This script generates two files. The first is the raw SQL file derived from the MySQL database but after the Sqlite-specific modifications have been made to the SQL. This file is useful for debugging in the event that your MySQL database contains data that Sqlite doesn't like and this script doesn't catch (a scenario which should throw all sorts of errors to the console).
The second file is the Sqlite database itself, generated by passing the above-mentioned SQL file through sqlite3.
== YAML CONFIG FILE
If you're familiar with Rails or Merb, this format will seem uncanny:
database: database_name
username: database_username
password: database_password
== OPTIONAL PARAMETERS
=== OVERWRITE
By default the script warns if if it is about to over-write already-existing files. However this can be explicitly configured via the following:
Command line: add "true" or "1" as the final parameter to over-write without warning:
./mysql2sqlite.rb database_name database_user database_password true
YAML file: add "true" as the 'overwrite' property to over-write without warning:
database: database_name
username: database_username
password: database_password
overwrite: true
=== TABLES
To explicitly specify which tables are to be output, add the table names to the YAML file:
database: database_name
username: database_username
password: database_password
overwrite: true
tables:
- users
- messages
- blog_posts
This parameter is not available via command-line configuration.
=== MYSQLDUMP
By default script use 'mysqldump' util. You may choose another:
database: database_name
username: database_username
password: database_password
mysqldump: /opt/local/bin/mysqldump5
== KNOWN ISSUES
I know this is version 0.2 and thus I suspect it is inefficient as all get-out and likely fails on some databases (in other words: currently, it works for me). That said, it cleanly dumps the entire Rails app I needed it to dump and the Sqlite database seems just dandy. Give it a try, let me know.
== EXPECTED FUTURE FEATURES
- Better exception handling (actually, any exception handling at all). Right now it just chokes or steamrollers when it runs into a problem (like spelling your db password incorrectly).
- The ability to exclude the intermediary SQL file via configuration (or perhaps make it opt-in).
== LICENSE
(The MIT License)
Copyright (c) Chris Cummer 2009
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Jump to Line
Something went wrong with that request. Please try again.