Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing a SQLite3 dump back into the database

I feel like this is a stupid question because it seems like common sense . . . but no google search I can put together seems to be able to give me the answer!

I know how to get data OUT of a sqlite3 database using the .dump command. But now that I have this ASCII file titled export.sqlite3.sql . . . I can't seem to get it back INTO the database I want.

My goal was to transfer the data I had in one rails app to another so I didn't have to take all sorts of time creating dummy data again . . . so I dumped the data from my first app, got rid of all the CREATE TABLE statements, and made sure my schema on my second app matches . . . now I just have to get it IN there.

Would anyone mind helping me out? And when you find a way, will you tell me what you plugged into the google, 'cause I am beating my head open with a spoon right now over what I thought would be an easy find.

like image 237
BushyMark Avatar asked Nov 22 '08 19:11

BushyMark


People also ask

How can we load data from a file to SQLite database?

First, from the menu choose tool menu item. Second, choose the database and table that you want to import data then click the Next button. Third, choose CSV as the data source type, choose the CSV file in the Input file field, and choose the ,(comma) option as the Field separator as shown in the picture below.

How do I backup and restore SQLite database?

One way to do it is to simply attach a new database using the backup file (or a copy of it). Another way to restore a database is to use the . restore dot command to restore the database file to your chosen database within SQLite CLI.

What is a SQLite dump file?

In SQLite Dump command is used to dump the databases, table's schema and tables data based on our requirements. By using SQLite Dump command we can save the structure and data of the database tables in SQL format to the disk.


2 Answers

cat dumpfile.sql | sqlite3 my_database.sqlite 

This is modified from the sqlite3 getting started guide.

like image 194
Ali Afshar Avatar answered Oct 01 '22 05:10

Ali Afshar


You didn't specify your operating system and while

sqlite3 my_database.sqlite < export.sqlite3.sql 

will work for the unix flavors, it will not work for windows.

The inverse of the .dump command is the .read command. The syntax would be

sqlite3> .read export.sqlite3.sql 
like image 42
Noah Avatar answered Oct 01 '22 04:10

Noah