SQLite導出整個數據庫/導出某個表到SQL文件

突然想導出SQLite數據庫的某個表的數據,然後就記錄一下:

執行“sqlite3.exe”,我們可能用到下面幾個命令:
sqlite> .help
.dump ?TABLE? ...      Dump the database in an SQL text format
                         If TABLE specified, only dump tables matching
                         LIKE pattern TABLE.
.exit                  Exit this program
.help                  Show this message
.open ?--new? ?FILE?   Close existing database and reopen FILE
                         The --new starts with an empty file
.output ?FILENAME?     Send output to FILENAME or stdout
.quit                  Exit this program
.read FILENAME         Execute SQL in FILENAME
.tables ?TABLE?        List names of tables
                         If TABLE specified, only list tables matching
                         LIKE pattern TABLE.
sqlite>

假設我們有一個SQLite數據庫文件,名爲db.sqlite3,這個數據庫中有2個表,分別爲tb1和tb2,
我們導出整個數據庫到db.SQL文件的方式:
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .open db.sqlite3
sqlite> .output db.SQL
sqlite> .dump
sqlite> .exit

我們導出表tb1到db.SQL文件的方式:
Use ".open FILENAME" to reopen on a persistent database.
sqlite> .open db.sqlite3
sqlite> .output db.SQL
sqlite> .dump tb1
sqlite> .exit
完。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章