如何恢复损坏的SQLite3数据库? [英] How to recover a corrupt SQLite3 database?

查看:203
本文介绍了如何恢复损坏的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?

感谢

推荐答案

如果有任何自动方法,SQLite就已经能够做到了。

If there were any automatic method, SQLite would already be able to do it.

有时,损坏只是或大部分在索引中,在这种情况下,通过尝试使用 .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数据库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆