A Byte of my 2.2-lb Brain

Just sharing stuff…

Malformed Database Disk Image

Every now and then, I encounter malformed database disk images, especially with sqlite3 files.

DatabseError: database disk image is malformed

To fix the error, the following methods worked for me. But before anything else, note the following files

  • mydb.sqlite – this is the corrupted database disk image
  • mynew.sqlite – this is the new database file that you have yet to create

First, load the sqlite3 terminal. On the command line, execute

$ sqlite3 mydb.sqlite

This will launch the sqlite prompt.

sqlite> .mode insert
sqlite> .output dump_all.sql
sqlite> .dump
sqlite> .exit

After exiting the sqlite terminal. Run the following code on the Terminal. Note that you are re-entering the sqlite prompt, but this time the argument is the new mynew.sqlite file.

$ sqlite3 mynew.sqlite

sqlite> .read dump_all.sql
sqlite> .exit

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


This entry was posted on May 2, 2015 by in Geek and tagged , , , .