SQLite 命令行工具sqlite3介绍
SQLite教程以最新的SQLite版本version 3.33.0(2020-08-20)为基础,带你学习和了解最新的SQLite语法及使用。本教程类含有大量的测试用例,都是本人亲测,简单好用,是你学习和参考的好帮手。
加入字节流官方QQ群:952873936或联系站长进行技术交流。
加入字节流官方QQ群:952873936或联系站长进行技术交流。
SQLite提供的命令行交互平台sqlite3(在Windows上为sqlite3.exe)命令行程序,允许用户针对SQLite数据库或ZIP存档手动输入和执行SQL语句。
在控制台下输入sqlite3命令,即可运行.
c:\bytekits\sqlite>sqlite3
SQLite version 3.33.0 2020-08-14 13:23:32
Enter ".help" for usage hints.
Connected to a transient in-memory database.
Use ".open FILENAME" to reopen on a persistent database.
sqlite>
进入sqlite3控制台程序后,可以看到输入提示为sqlite>
。
如想退出,输入.quit
即可退出sqlite3命令提示行。
sqlite> .quit
c:\bytekits\sqlite>
sqlite3命令
进入sqlite3命令提示行后,通这提示可以看到,输入.help
命令本看帮助。
sqlite> .help
面的命令会显示各种重要的 SQLite 点命令的列表,如下所示:
命令 | 描述(英文) | 描述(中文) |
---|---|---|
.archive … | Manage SQL archives | 管理SQL档案 |
.auth ON|OFF | Show authorizer callbacks | |
.backup ?DB? FILE | Backup DB (default “main”) to FILE | 备份 DB 数据库(默认是 “main”)到 FILE 文件。 |
.bail on|off | Stop after hitting an error. Default 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 | 复制当前数据库到新的数据库 |
.databases | List names and files of attached databases | 列出数据库的名称及其所依附的文件。 |
.dbconfig ?op? ?val? | List or change sqlite3_db_config() options | |
.dbinfo ?DB? | Show status information about the database | 显示数据库信息 |
.dump ?TABLE? | Render database content as SQL | 以 SQL 文本格式转储数据库。如果指定了 TABLE 表,则只转储匹配 LIKE 模式的 TABLE 表。 |
.echo on|off | Turn command echo on or off | 开启或关闭 echo 命令 |
.eqp on|off|full|… | Enable or disable automatic EXPLAIN QUERY PLAN | |
.excel | Display the output of next command in spreadsheet | 将数据导出到excel文件 |
.exit ?CODE? | Exit this program with return-code CODE | 退出 SQLite 提示符。 |
.expert | EXPERIMENTAL. Suggest indexes for queries | |
.explain ?on|off|auto? | Change the EXPLAIN formatting mode. Default: auto | 开启或关闭适合于 EXPLAIN 的输出模式。如果没有带参数,则为 EXPLAIN on,即开启 EXPLAIN。 |
.filectrl CMD … | Run various sqlite3_file_control() operations | |
.fullschema ?—indent? | Show schema and the content of sqlite_stat tables | |
.headers on|off | Turn display of headers on or off | 开启或关闭头部显示。 |
.help ?-all? ?PATTERN? | Show help text for PATTERN | 显示消息。 |
.import FILE TABLE | Import data from FILE into TABLE | 导入来自 FILE 文件的数据到 TABLE 表中。 |
.imposter INDEX TABLE | Create imposter table TABLE on index INDEX | |
.indexes ?TABLE? | Show names of indexes | 显示所有索引的名称。如果指定了 TABLE 表,则只显示匹配 LIKE 模式的 TABLE 表的索引。 |
.limit ?LIMIT? ?VAL? | Display or change the value of an SQLITE_LIMIT | |
.lint OPTIONS | Report potential schema issues. | |
.load FILE ?ENTRY? | Load an extension library | 加载一个扩展库。 |
.log FILE|off | Turn logging on or off. FILE can be stderr/stdout | 开启或关闭日志。FILE 文件可以是 stderr(标准错误)/stdout(标准输出)。 |
.mode MODE ?TABLE? | Set output mode | 设置输出模式。常用的如html,column,json,list |
.nullvalue STRING | Use STRING in place of NULL values | 在 NULL 值的地方输出 STRING 字符串。 |
.once ?OPTIONS? ?FILE? | Output for the next SQL command only to FILE | 将下一条sql命令输出到文件 |
.open ?OPTIONS? ?FILE? | Close existing database and reopen FILE | 关闭当前数据库,重新加载新的数据库 |
.output ?FILE? | Send output to FILE or stdout if FILE is omitted | 发送输出到stdout或文件。 |
.parameter CMD … | Manage SQL parameter bindings | 管理sql参数绑定信息 |
.print STRING… | Print literal STRING | 逐字地输出 STRING 字符串。 |
.progress N | Invoke progress handler after every N opcodes | |
.prompt MAIN CONTINUE | Replace the standard prompts | 替换标准提示符。 |
.quit | Exit this program | 退出 SQLite 提示符。 |
.read FILE | Read input from FILE | 执行 FILENAME 文件中的 SQL。 |
.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 | 设置sqlite3_stmt_scanstatus打开与关闭 |
.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 | 改变输出模式和 .import 所使用的分隔符。 |
.sha3sum … | Compute a SHA3 hash of database content | 计算数sha3 |
.shell CMD ARGS… | Run CMD ARGS… in a system shell | 运行系统命令 |
.show | Show the current values for various settings | 显示各种设置的当前值。 |
.stats ?on|off? | Show stats or turn stats on or off | 开启或关闭统计 |
.system CMD ARGS… | Run CMD ARGS… in a system shell | 运行系统命令 |
.tables ?TABLE? | List names of tables matching LIKE pattern TABLE | 列出匹配 LIKE 模式的表的名称。 |
.testcase NAME | Begin redirecting output to ‘testcase-out.txt’ | 重定向输出文件 |
.testctrl CMD … | Run various sqlite3_test_control() operations | 运行各种sqlite3_test_control()操作 |
.timeout MS | Try opening locked tables for MS milliseconds | 尝试打开锁定的表 MS 毫秒。 |
.timer on|off | Turn SQL timer on or off | 开启或关闭 CPU 定时器。 |
.trace ?OPTIONS? | Output each SQL statement as it is run | SQL语句跟踪 |
.vfsinfo ?AUX? | Information about the top-level VFS | 虚拟文件系统信息 |
.vfslist | List all available VFSes | 显示所有可用的VFSes |
.vfsname ?AUX? | Print the name of the VFS stack | 打印VFS栈 |
.width NUM1 NUM2 … | Set minimum column widths for columnar output | 为 “column” 模式设置列宽度。 |
字节流是站长多年来的工作经验和技术总结,和站长一起学习,每天都有进步。
通俗易懂,深入浅出。
文章不深奥,不需要钻研,不烧脑细胞,人人都可以学习,在公交、在地铁、在厕所都可以阅读,随时随地涨姿势。
通俗易懂,深入浅出。
文章不深奥,不需要钻研,不烧脑细胞,人人都可以学习,在公交、在地铁、在厕所都可以阅读,随时随地涨姿势。