Python script to fill a SQLite DB file by SQL dump and write content as CSV.
- Execute SQL statements directly or from files
- Create a SQLite DB file if necessary
- Convert SQL dumps to SQLite-compatible format
- View database schema
- Export tables to CSV files
python sql2csv.py [-h] [-a DIRECTORY] [-c COLUMN NAME / STRING] [-d CHAR / STRING]
[-e SQL STATEMENT / STRING] [-f SQL FILE] [-g] [-l] [-n INTEGER]
[-r PATH] [-s] [-t TABLE NAME / STRING] [-w FILE]
FILE
FILE
: SQLite database file path
-a, --all DIRECTORY
: Export all tables to CSV files in the specified directory-c, --column COLUMN
: Select a specific column (requires-t/--table
)-d, --delimiter CHAR
: Set delimiter between columns (default: tab)-e, --execute SQL
: Execute SQL statement-f, --file PATH
: Execute SQL statements from file with SQLite compatibility translation-g, --debug
: Enable debug mode (gives output on -e/--execute, -f/--file or -r/--read)-l, --headless
: Omit headers/field names in output-n, --lines INTEGER
: Limit output to n lines (0 for headers only)-r, --read PATH
: Execute SQL statements from file without translation-s, --schema
: Print database schema-t, --table TABLE
: Select table to export-w, --write FILE
: Write output to file instead of stdout
python sql2csv.py sqlite.db -e "CREATE TABLE table_name (col1_name, col2_name);"
python sql2csv.py sqlite.db -f dump.sql
python sql2csv.py sqlite.db -s
python sql2csv.py sqlite.db -t table_name -w outfile.csv
python sql2csv.py sqlite.db -t table_name -c column_name -w outfile.csv
python sql2csv.py sqlite.db -a ./exports
Choose an unused file name for sqlite.db to convert dump.sql directly into CSV files
python sql2csv.py sqlite.db -f dump.sql -a ./exports
Respect GPL-3: https://www.gnu.org/licenses/gpl-3.0.en.html
Use the software on your own risk.
This is not a commercial product with an army of developers and a department for quality control behind it.