加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Sqlite3 导出/导入SQL语句

发布时间:2020-12-12 19:54:06 所属栏目:百科 来源:网络整理
导读:前言 Sqlite3 提供了较轻便的数据库操作,速度非常快,也比较稳定,在嵌入式产品中用的非常广泛,但嵌入式产品往往由于不稳定性因素非常多,备份是必不可少的,直接拷贝 .db 文件并不是太好的主意,所以引出本文所要讲的主题: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语句即可。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读