Exporting SQLite Database


Database as SQL

To dump the entire database content in SQL for example for a backup run:

sqlite3 <database_file> .dump >output.sql

See the next sections how to dump a single table or in SQL.

Table as SQL

To dump the SQL to create a table and its values run the command line client using the “.dump” command an redirect the output:

sqlite3 <database_file> ".dump <table_name>" >output.sql

Table as CSV

To dump the SQL to create a table and its values run the command line client using the “.mode” command to enable CSV output and then to perform a “SELECT” on the table you want to dump. By echoing this to the CLI you can easily redirect the output:

echo ".mode csv select * from;" | sqlite3 >output.sql

Published by

admin

Computer Engineer