How to recover a corrupt SQLite3 database?

前端 未结 12 2103
走了就别回头了
走了就别回头了 2020-11-28 03:46

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

12条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-28 03:58

    UPDATE: There is now an automatic method that is built into SQLite: .recover

    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.

提交回复
热议问题