how to export sqlite3 db to SQL

5
(1)

The shell allows redirection, and sqlite3 can get the command as a parameter:

sqlite3 test.db .schema > schema.sql

or

sqlite3 test.db <<EOF
.output schema.sql
.schema
EOF

For example, you can export only the schema of apple.db to backup.sql with .schema as shown below.

sqlite3 apple.db .schema > backup.sql

And, you can export only the schema of apple.db to backup.sql with the commands below. *.output creates and selects or only selects a file depending on the file existence and you must exit to close the file (e.g., .exit or .quit) otherwise the results of SQLite commands are output to the file:

sqlite3 apple.db
sqlite> .output backup.sql
sqlite> .schema
sqlite> .exit

And, you can export only the schema of the specific tables in apple.db to backup.sql with the commands below. *.schema exports the schema of only one specific table so you should run .schema multiple times if you want to export the schema of the specific multiple tables:

sqlite3 apple.db
sqlite> .output backup.sql
sqlite> .schema person
sqlite> .schema animal
sqlite> .exit
315

How useful was this post?

Click on a star to rate it!

Average rating 5 / 5. Vote count: 1

No votes so far! Be the first to rate this post.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top