Sqlite3 导出/导入SQL语句

前言

Sqlite3 提供了较轻便的数据库操作,速度非常快,也比较稳定,在嵌入式产品中用的非常广泛,但嵌入式产品往往由于不稳定性因素非常多,备份是必不可少的,直接拷贝 .db 文件并不是太好的主意,所以引出本文所要讲的主题:Sqlite3 导入/导出SQL 语句。


导出

root@CATON:~# sqlite3 db/boardsprofile.db 
SQLite version 3.6.0
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables   
A04Profile      BPMProfile      HDERProfile     LNBProfile      VMUX          
A13Profile      CAMProfile      HDESLProfile    LNBTProfile     router_table  
A22Profile      DDOProfile      IPASIINProfile  MDOProfile      system_profile
A31Profile      DSDE1VProfile   IPASIProfile    MUXProfile    
A40Profile      DSDEProfile     IPMOutProfile   MVProfile     
ADOProfile      HDDOProfile     IPMProfile      P1            
ASDEProfile     HDELProfile     LNBBissProfile  P6            
sqlite> 

我使用的SQLite版本是 3.6.0 , 其他也是类似的,通过.tables 可以看到所有的表类型。

sqlite> .dump                  
BEGIN TRANSACTION;
CREATE TABLE DDOProfile  (key varchar(255) PRIMARY KEY , value text);
INSERT INTO "DDOProfile" VALUES('boardType','DDOProfile');
INSERT INTO "DDOProfile" VALUES('main_input_num','0');
INSERT INTO "DDOProfile" VALUES('main_output_num','0');
INSERT INTO "DDOProfile" VALUES('sub_input_num','1');
INSERT INTO "DDOProfile" VALUES('sub_output_num','0');
INSERT INTO "DDOProfile" VALUES('sub_in_0','1');
INSERT INTO "DDOProfile" VALUES('PlaySrc0','');
INSERT INTO "DDOProfile" VALUES('Default_Pict0','3');
INSERT INTO "DDOProfile" VALUES('AVSync','0');
INSERT INTO "DDOProfile" VALUES('Decoder_WorkMode','0');
INSERT INTO "DDOProfile" VALUES('Output_Format','3');
INSERT INTO "DDOProfile" VALUES('Aspect_Ratio','0');
INSERT INTO "DDOProfile" VALUES('AR_Convert','0');
INSERT INTO "DDOProfile" VALUES('Aud_Mute','0');
INSERT INTO "DDOProfile" VALUES('Aud_Level','32');
INSERT INTO "DDOProfile" VALUES('Aud_STCOffset','0');
INSERT INTO "DDOProfile" VALUES('Aud_Buff','0');
INSERT INTO "DDOProfile" VALUES('Aud_Mode','0');
INSERT INTO "DDOProfile" VALUES('Aud_DigitalOut','0');
INSERT INTO "DDOProfile" VALUES('Aud2_Mute','0');
INSERT INTO "DDOProfile" VALUES('Aud2_Level','32');
INSERT INTO "DDOProfile" VALUES('Aud2_STCOffset','0');
INSERT INTO "DDOProfile" VALUES('Aud2_Buff','0');
....


.dump 命令就是导出了,这里直接导出到输出了,而且非常多。导出到文件将是这样的:

sqlite3 db/boardsprofile.db ".dump" > /var/ftp/profile.sql
非常完整的整个整个数据库的SQL语句。


导入

sqlite3 test.db ".read /var/ftp/profile.sql"  

非常简单了。结果如下:

root@CATON:~# sqlite3 test.db ".read /var/ftp/profile.sql"              
root@CATON:~# sqlite3 test.db  
SQLite version 3.6.0
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> .tables
A04Profile      BPMProfile      HDERProfile     LNBProfile      VMUX          
A13Profile      CAMProfile      HDESLProfile    LNBTProfile     router_table  
A22Profile      DDOProfile      IPASIINProfile  MDOProfile      system_profile
A31Profile      DSDE1VProfile   IPASIProfile    MUXProfile    
A40Profile      DSDEProfile     IPMOutProfile   MVProfile     
ADOProfile      HDDOProfile     IPMProfile      P1            
ASDEProfile     HDELProfile     LNBBissProfile  P6            
sqlite> 

profile.sql 这个文件可以方便的导入到 mysql , sql server中,任何数据库皆通用了。


用处

让用户直接下载db文件并不是一个很好的决定,用户备份,我比较倾向于,保存sql语句即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值