Linux command
sqlite3 命令
文本
复制后可按需替换文件名、目录或参数。
常用示例
Open or create a database
sqlite3 [database.db]
Execute a SQL query
sqlite3 [database.db] "[SELECT * FROM table]"
Execute SQL from a file
sqlite3 [database.db] < [query.sql]
Export query results to CSV
sqlite3 -csv [database.db] "[SELECT * FROM table]" > [output.csv]
Show all tables
sqlite3 [database.db] ".tables"
Show table schema
sqlite3 [database.db] ".schema [table_name]"
Import CSV into table
sqlite3 [database.db] ".import [file.csv] [table_name]"
Open in-memory database
sqlite3 :memory:
说明
sqlite3 is the command-line interface for SQLite, a self-contained, serverless SQL database engine. SQLite databases are single files that can be easily shared and backed up. The tool provides both interactive and batch modes. In interactive mode, enter SQL statements ending with semicolons or dot commands for administrative functions. Batch mode processes SQL from arguments or stdin. SQLite supports most SQL features including transactions, triggers, views, and complex queries. It's embedded in countless applications and is ideal for local storage, testing, and small-scale applications.
参数
- -csv
- Set output mode to CSV
- -json
- Set output mode to JSON
- -column
- Set output mode to column format
- -header
- Include column headers in output
- -line
- Set output mode to one value per line
- -separator _sep_
- Set field separator for CSV mode
- -init _file_
- Execute SQL from file at startup
- -batch
- Batch mode; exit on error
- -readonly
- Open database in read-only mode
- -version
- Show version information
FAQ
What is the sqlite3 command used for?
sqlite3 is the command-line interface for SQLite, a self-contained, serverless SQL database engine. SQLite databases are single files that can be easily shared and backed up. The tool provides both interactive and batch modes. In interactive mode, enter SQL statements ending with semicolons or dot commands for administrative functions. Batch mode processes SQL from arguments or stdin. SQLite supports most SQL features including transactions, triggers, views, and complex queries. It's embedded in countless applications and is ideal for local storage, testing, and small-scale applications.
How do I run a basic sqlite3 example?
Run `sqlite3 [database.db]` in a terminal, then adjust file names, paths, flags, or remote targets for your system.
What does -csv do in sqlite3?
Set output mode to CSV