這是歷史版本頁面 — 看 SQLite (64-bit) 最新版本

SQLite 64位是什麼?輕量資料庫怎麼用

SQLite (64-bit) 軟體圖示 SQLite (64-bit) 3.21.0 (64-bit) 資料更新 2017-10-25 閱讀約 5 分鐘

寫個小工具或網站,需要把資料存下來,但想到要裝 MySQL 或 SQL Server 就頭痛——安裝程式好幾百 MB,設定服務、開 port、設帳號密碼,光前置作業就耗掉半天。你只是想讓程式把資料寫進檔案、之後能查得出來,不想為此養一台資料庫伺服器。

用 Excel 或 CSV 檔存資料,一開始很直覺,但資料一多、要跨表格比對或做條件篩選時,就開始卡。這類工具的切入點是「嵌入式資料庫」:不需要獨立伺服器,資料全部存在單一檔案裡,程式直接讀寫這個檔案,零設定、免安裝、離線可用。你要的只是把 SQL 查詢能力帶進你的應用程式,而不是管理一套資料庫系統。

01SQLite 64位能做什麼?

它是一個嵌入式資料庫引擎,不需要獨立伺服器,資料存在單一檔案中。你可以用 SQL 指令建立資料庫、建立表格、插入資料、查詢資料,支援大部分 SQL 標準,包括子查詢、JOIN 和觸發器。適合應用程式的本地儲存、行動裝置和嵌入式系統,例如桌面軟體的設定檔、遊戲存檔、分析工具的暫存資料。

02怎麼建立資料庫和表格?

下載 ZIP 檔解壓縮後,執行 sqlite3.exe,輸入 `sqlite3 database_name.db` 就會建立一個新的資料庫檔案。建立表格用 `CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);`,插入資料用 `INSERT INTO users (name) VALUES ('John Doe');`,查詢用 `SELECT * FROM users;`。整個過程不需要任何設定。

03支援哪些 SQL 功能?

支援大部分 SQL 標準,包括子查詢、JOIN、觸發器,也具備完整的 ACID 交易保證,確保資料完整性。資料庫最大可達 281TB,但實際效能會依硬體和查詢複雜度而異。官方文件相當完整,語法與其他關聯式資料庫類似,學過 SQL 的人可以很快上手。

04資料庫檔案可以多大?

官方說明指出最大可達 281TB,但效能會隨資料量增加而下降。對一般應用程式的本地儲存來說,幾 GB 到幾十 GB 都還算常見使用範圍。如果資料量極大且查詢複雜,效能衰減會很明顯,這套軟體不是為超大規模資料設計的。

05怎麼匯出資料?

在 sqlite3 命令列中,先輸入 `.mode csv` 設定輸出格式,再輸入 `.output file.csv` 指定輸出檔案,最後執行 `SELECT * FROM users;`,查詢結果就會寫入 CSV 檔案。要回到螢幕輸出時,輸入 `.output stdout` 即可。這是內建功能,不需要額外工具。

06需要安裝嗎?

不需要。下載 ZIP 檔後解壓縮到任意資料夾就能執行,也可以把資料夾加入系統的 PATH 環境變數,方便從任何位置呼叫 sqlite3.exe。整個過程完全離線運作,不需要網路連線,也沒有任何背景服務或常駐程式。

07免費嗎?

是,SQLite 採用公共領域授權,完全免費,任何人可以無限制使用,包含商業用途。不過,如果你需要加密功能,官方提供的 SQLite Encryption Extension(SEE)需要付費授權;另一個選擇是開源的 SQLCipher,但這不在官方預設支援範圍內,需要自行整合。

08多人同時使用適合嗎?

不適合。SQLite 設計用於本地儲存,雖然支援多個連線,但不是為高流量並發環境最佳化。多人同時寫入時可能遇到鎖定問題,官方說明也明確指出它不適合高並發環境。如果你的應用需要多人同時讀寫,應該考慮 MySQL 或 PostgreSQL 這類完整 RDBMS。

09有圖形介面嗎?

SQLite 本身沒有圖形介面,只有命令列工具。官方說明提到可以搭配第三方 GUI 工具,例如 DB Browser for SQLite 或 SQLiteStudio,這些工具提供圖形化的資料庫結構檢視,方便瀏覽表格、執行查詢、匯入匯出資料。如果你習慣視覺化操作,需要另外下載這些工具。

10需要使用者管理嗎?

不需要,SQLite 沒有內建認證或使用者管理功能。資料庫就是一個檔案,任何能存取該檔案的人都能讀寫全部內容。如果你的應用需要區分使用者權限,必須在應用層自行實作,或改用有內建帳號管理的資料庫系統。這對單機應用不是問題,但對多人共享的環境就是限制。

11資料量很大適合嗎?

不適合。官方說明指出,資料量很大時效能會下降,而且不適合大規模多使用者應用。它擅長的是單一使用者或嵌入式場景,例如應用程式本地儲存、行動裝置、小型工具。如果你的資料預期會成長到數十 GB 以上,或需要多人同時查詢,應該評估其他資料庫方案。

下載與官方連結

前往官方網站 下載 SQLite (64-bit)

sqlite-dll-win64-x64-3210000.zip · 連結指向軟體原廠

版本紀錄

再看 5 筆

看完整版本清單

這一版改了什麼

What's new in this version:

- Take advantage of the atomic-write capabilities in the F2FS filesystem when available, for greatly reduced transaction overhead. This currently requires the SQLITE_ENABLE_BATCH_ATOMIC_WRITE compile-time option
- Allow ATTACH and DETACH commands to work inside of a transaction
- Allow WITHOUT ROWID virtual tables to be writable if the PRIMARY KEY contains exactly one column
-The "fsync()" that occurs after the header is written in a WAL reset now uses the sync settings for checkpoints. This means it will use a "fullfsync" on macs if PRAGMA checkpoint_fullfsync set on
-The sqlite3_sourceid() function tries to detect if the source code has been modified from what is checked into version control and if there are modifications, the last four characters of the version hash are shown as "alt1" or "alt2". The objective is to detect accidental and/or careless edits. A forger can subvert this feature
-Improved de-quoting of column names for CREATE TABLE AS statements with an aggregate query on the right-hand side
-Fewer "stat()" system calls issued by the unix VFS
-Enhanced the LIKE optimization so that it works with an ESCAPE clause
-Enhanced PRAGMA integrity_check and PRAGMA quick_check to detect obscure row corruption that they were formerly missing. Also update both pragmas so that they return error text rather than SQLITE_CORRUPT when encountering corruption in records
- The query planner now prefers to implement FROM-clause subqueries using co-routines rather using the query flattener optimization. Support for the use of co-routines for subqueries may no longer be disabled
- Pass information about !=, IS, IS NOT, NOT NULL, and IS NULL constraints into the xBestIndex method of virtual tables
- Enhanced the CSV virtual table so that it accepts the last row of input if the final new-line character is missing
- Remove the rarely-used "scratch" memory allocator. Replace it with the SQLITE_CONFIG_SMALL_MALLOC configuration setting that gives SQLite a hint that large memory allocations should be avoided when possible
- Added the swarm virtual table to the existing union virtual table extension
- Added the sqlite_dbpage virtual table for providing direct access to pages of the database file. The source code is built into the amalgamation and is activated using the -DSQLITE_ENABLE_DBPAGE_VTAB compile-time option
- Add a new type of fts5vocab virtual table - "instance" - that provides direct access to an FTS5 full-text index at the lowest possible level
- Remove a call to rand_s() in the Windows VFS since it was causing problems in Firefox on some older laptops
- The src/shell.c source code to the command-line shell is no longer under version control. That file is now generated as part of the build process
- Miscellaneous microoptimizations reduce CPU usage by about 2.1%

Bug fixes:
- Fix a faulty assert() statement discovered by OSSFuzz
- Fix an obscure memory leak in sqlite3_result_pointer()
- Avoid a possible use-after-free error by deferring schema resets until after the query planner has finished running
- Only use indexes-on-expressions to optimize ORDER BY or GROUP BY if the COLLATE is correct
- Fix an assertion fault that was coming up when the expression in an index-on-expressions is really a constant
- Fix an assertion fault that could occur following PRAGMA reverse_unordered_selects
- Fix a segfault that can occur for queries that use table-valued functions in an IN or EXISTS subquery
- Fix a potential integer overflow problem when compiling a particular horrendous common table expression. This was another problem discovered by OSSFuzz
- Fix a potential out-of-bound read when querying a corrupt database file, a problem detected by Natalie Silvanovich of Google Project Zero