sqlite的基本使用

1、登录

sqlite  da_name

2、查看数据库和表

.databases

.tables

3、查看表结构

.schema  tablename

4、导入数据到sqlite

  1. sqlite> .separator "," 
  2. sqlite> .import data.txt data_txt_table
  3. sqlite> select * from data_txt_table;
  4. id,name,age,address,hobby
  5. 1,tom,24,beijing,football
  6. 2,liu,27,heibei,fotball
  7. 3,jim,26,shandong,football
  8. 4,han,28,beijing,football
  9. 5,meng,25,beijing,tennis
  10. sqlite>

5、数据导出

数据导出也是一个常用到的操作,可以将指定表中的数据导出成SQL脚本,供其他数据库使用,还可以将指定的数据表中的数据完整定位到标准输出,也可以将指定数据库中的数据完整的导入到另一个指定数据库等,

1. 导出成指定的SQL脚本
   将sqlite中指定的数据表以SQL创建脚本的形式导出,具体命令

  1. ywx@ywx:~/yu/sqlite$ sqlite3 test.db
  2. SQLite version 3.7.7.1 2011-06-28 17:39:05
  3. Enter ".help" for instructions
  4. Enter SQL statements terminated with a ";"
  5. sqlite> .output data.sql
  6. sqlite> .dump
  7. sqlite>
    1. ywx@ywx:~/yu/sqlite$ ll
    2. 总计 16
    3. drwxr-xr-x 2 ywx ywx 4096 2011-08-13 23:15 ./
    4. drwxr-xr-x 7 ywx ywx 4096 2011-08-13 20:53 ../
    5. -rw-r--r-- 1 ywx ywx 602 2011-08-13 23:17 data.sql
    6. -rw-r--r-- 1 ywx ywx 2048 2011-08-13 22:44 test.db
原文地址:https://www.cnblogs.com/ljy2013/p/6283036.html