您的位置:首页 > 数据库

SQLite导出整个数据库/导出某个表到SQL文件

2016-12-27 20:17 393 查看
突然想导出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完。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: