How to recover a corrupt SQLite3 database?(如何恢复损坏的 SQLite3 数据库?)
问题描述
这是之前回答的帖子的后续问题:是否有用于在 Linux 中验证 SQLite 数据库的命令行实用程序?
This is a follow up question to a previously answered post: Is there a command line utility for validating SQLite databases in Linux?
如果数据库产生以下错误:
If a database is producing the following error:
$ sqlite3 mydata.db "PRAGMA integrity_check"
Error: database disk image is malformed
是否有任何清理处理可以将数据库恢复到可用状态?即使可能会丢失一些损坏的记录?
Is there any cleanup processing that can be done to recover the database to a usable state? Even at the potential loss of some corrupt records?
谢谢
推荐答案
UPDATE:现在有一个自动方法内置于 SQLite:.recover
UPDATE: There is now an automatic method that is built into SQLite: .recover
有时,损坏仅或大部分出现在索引中,在这种情况下,通过尝试使用 .dump 转储整个数据库,可以获取部分或大部分记录,并使用这些命令来创建一个新的数据库:
Sometimes, the corruption is only or mostly in indexes, in which case it would be possible to get some or most records by trying to dump the entire database with .dump, and use those commands to create a new database:
$ sqlite3 mydata.db ".dump" | sqlite3 new.db
然而,这并不总是可行的.
However, this is not always possible.
最简单、最可靠的方法是从备份中恢复数据库文件.
The easiest and most reliable way is to restore the database file from the backup.
这篇关于如何恢复损坏的 SQLite3 数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何恢复损坏的 SQLite3 数据库?
基础教程推荐
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 带有WHERE子句的LAG()函数 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
