How to import load a .sql or .csv file into SQLite?

happythenewsad picture happythenewsad · Jun 25, 2009 · Viewed 171.7k times · Source

I need to dump a .sql or .csv file into SQLite (I'm using SQLite3 API). I've only found documentation for importing/loading tables, not entire databases. Right now, when I type:

sqlite3prompt> .import FILENAME TABLE 

I get a syntax error, since it's expecting a table and not an entire DB.

Answer

Jay Igor picture Jay Igor · Jun 25, 2009

To import from an SQL file use the following:

sqlite> .read <filename>

To import from a CSV file you will need to specify the file type and destination table:

sqlite> .mode csv <table>
sqlite> .import <filename> <table>