玩转SQLite2:SQLite命令行基本操作
本篇介绍SQLite的命令行基本操作
1 SQLite 点命令
SQLite 的点命令,是一些以点为开头的命令:
完整的点指令如下:
.archive ...
Manage SQL archives.auth ON|OFF
Show authorizer callbacks.backup ?DB? FILE
备份DB数据库(默认是 "main")到 FILE 文件.bail on|off
发生错误后停止,默认为 OFF.binary on|off
Turn binary output on or off. Default OFF.cd DIRECTORY
Change the working directory to DIRECTORY.changes on|off
Show number of rows changed by SQL.check GLOB
Fail if output since .testcase does not match.clone NEWDB
Clone data into NEWDB from the existing database.connection [close] [#]
Open or close an auxiliary database connection.databases
列出数据库的名称及其所依附的文件.dbconfig ?op? ?val?
List or change sqlite3_db_config() options.dbinfo ?DB?
Show status information about the database.dump ?OBJECTS?
以 SQL 文本格式转储数据库.echo on|off
开启或关闭 echo 命令.eqp on|off|full|...
Enable or disable automatic EXPLAIN QUERY PLAN.excel
Display the output of next command in spreadsheet.exit ?CODE?
以CODE码退出SQLite提示符.expert
EXPERIMENTAL. Suggest indexes for queries.explain ?on|off|auto?
开启或关闭适合于 EXPLAIN 的输出模式,默认是:auto.filectrl CMD ...
Run various sqlite3_file_control() operations.fullschema ?--indent?
Show schema and the content of sqlite_stat tables.headers on|off
开启或关闭头部显示.help ?-all? ?PATTERN?
显示帮助.import FILE TABLE
导入来自 FILE 文件的数据到 TABLE 表中.imposter INDEX TABLE
Create imposter table TABLE on index INDEX.indexes ?TABLE?
显示所有索引的名称.limit ?LIMIT? ?VAL?
Display or change the value of an SQLITE_LIMIT.lint OPTIONS
Report potential schema issues..load FILE ?ENTRY?
加载一个扩展库.log FILE|off
开启或关闭日志,可以是stderr或stdout.mode MODE ?TABLE?
设置输出模式.nonce STRING
Disable safe mode for one command if the nonce matches.nullvalue STRING
在 NULL 值的地方输出 STRING 字符串.once ?OPTIONS? ?FILE?
Output for the next SQL command only to FILE.open ?OPTIONS? ?FILE?
关闭存在的数据库或重新打开文件.output ?FILE?
Send output to FILE or stdout if FILE is omitted.parameter CMD ...
Manage SQL parameter bindings.print STRING...
逐字地输出 STRING 字符串.progress N
Invoke progress handler after every N opcodes.prompt MAIN CONTINUE
替换标准提示符.quit
退出 SQLite 提示符.read FILE
Read input from FILE.recover
Recover as much data as possible from corrupt db..restore ?DB? FILE
Restore content of DB (default "main") from FILE.save FILE
Write in-memory database into FILE.scanstats on|off
Turn sqlite3_stmt_scanstatus() metrics on or off.schema ?PATTERN?
Show the CREATE statements matching PATTERN.selftest ?OPTIONS?
Run tests defined in the SELFTEST table.separator COL ?ROW?
Change the column and row separators.session ?NAME? CMD ...
Create or control sessions.sha3sum ...
Compute a SHA3 hash of database content.shell CMD ARGS...
Run CMD ARGS... in a system shell.show
显示各种设置的当前值.stats ?ARG?
开启或关闭统计.system CMD ARGS...
Run CMD ARGS... in a system shell.tables ?TABLE?
List names of tables matching LIKE pattern TABLE.testcase NAME
Begin redirecting output to 'testcase-out.txt'.testctrl CMD ...
Run various sqlite3_test_control() operations.timeout MS
尝试打开锁定的表 MS 毫秒.timer on|off
开启或关闭SQL定时器.trace ?OPTIONS?
Output each SQL statement as it is run.vfsinfo ?AUX?
Information about the top-level VFS.vfslist
List all available VFSes.vfsname ?AUX?
Print the name of the VFS stack.width NUM1 NUM2 ...
Set minimum column widths for columnar output
例如,使用.show
指令可以查看当前的各种设置:
2 SQLite 创建数据库
使用sqlite3 命令来创建数据库有两种方式
2.1 方式1:sqlite3+数据库名
例如,使用sqlite3 test1.db
创建test1数据库,然后使用.databases
查看数据库
.
2.2 方式2:使用.open
命令
例如,使用.open test2.db
创建test2数据库
2.3 将数据库导出到文件
使用 .dump
点命令导出数据库到文本文件中
sqlite3 test1.db .dump > test1.sql
相关文章