Orange is my favorite color

About a week ago, Firefox 3 would no longer seem to hold any cookies. I would log in to my regular sites and say “remember me” and yet the next time I started Firefox, I was back to square one, re-entering my information over and over. It kept losing the cookies and forgetting who I was!

This ranged from odd the first day, to strange the second, to mildly annoying the third. By the time I got into the office this morning, I was ready to reinstall but that seemed excessive so I went searching. I came across a Mozilla Support thread which identified the issue as a corrupted sqlite database in Firefox 3. The solution was to close Firefox, rename the file and start it again, effectively removing the corrupted file and starting over. That’s good but what if you want to recover your previous cookies?

Recovering your cookies

The process is fairly simple although the amount of recovery possible will vary depending on where your sqlite database is corrupt. In my case, I was able to recover about 1050 cookies which is a lot better than nothing. Here’s what you need (my examples are Windows-based):

  1. Close Firefox
  2. Go to your Firefox profile directory, rename cookies.sqlite to was_cookies.sqlite
  3. First, confirm that a corrupted sqlite database is your problem. Restart Firefox and test by logging into a site, clicking remember me, closing FF and then opening it and going back to the site. Your freshly created cookies.sqlite should be working and you will have been automatically logged in. If not, you’re probably facing some other issue beyond the scope of this guide. Close Firefox and rename was_cookies.sqlite back to cookies.sqlite and look elsewhere. If this did work, then continue on…
  4. Download the SQLite binary for your platform and extract it into your profile directory
  5. Start it:
    > sqlite3.exe was_cookies.sqlite
    SQLite version 3.6.13
    Enter ".help" for instructions
  6. See how many records you can retrieve before it fails: sqlite> select count(*) from moz_cookies;
  7. If you want to proceed, export the cookies:
    sqlite> .mode insert moz_cookies
    sqlite> .output was_cookies_insert_sql
    sqlite> select * from moz_cookies;
    SQL error: database disk image is malformed
    sqlite> .quit
  8. Now load the current cookies.sqlite file and import your saved cookies:
    > sqlite3.exe cookies.sqlite
    SQLite version 3.6.13
    Enter ".help" for instructions
    Enter SQL statements terminated with a ";"
    sqlite> .read was_cookies_insert_sql
    sqlite> select count(*) from moz_cookies;
    1058
    sqlite> .quit
  9. Ok, you should be good to go. Restart Firefox 3 and try going back to your sites. Remember, it probably didn’t recover all of them so it’s quite likely at least some of the sites that used to log you in automatically or store your preferences will no longer be in your cookies.

Hope that helps!

10 Comments

  1. Dan G. Switzer, II said:

    on April 15, 2009 at 10:51 am

    On a sort of related note, if you don’t want to download the binary and go the pure command line route, there’s an excellent GUI for SQLlite at:

    http://sourceforge.net/projects/sqlitebrowser/

    What I like is there’s no install. Just extract and run. I use it quite a bit when I need to edit data in a SQLlite database.

  2. John Machin said:

    on May 26, 2009 at 3:26 am

    A few problems here:
    (1) “select count(*) from table_name” may fail without producing a count
    (2) select * from table_name; will typically stop at the FIRST corruption leaving only a fraction of rows recovered e.g. 74 out of 800+ in a cookies.sqlite that I have. The 800+ rows are easily recoverable if you ignore the SQLite library and get doen to the metal.
    (3) sqlitebrowser doesn’t put out an error message if the db is corrupt; it just silently returns the 74 cookies … in another case of a corrupt file it produced rubbish, again silently.

  3. brian said:

    on May 26, 2009 at 8:21 am

    @John – all possible, sounds like there are variants on this issue. The good news is that Mozilla released an update to Firefox awhile back that specifically addressed this issue. Since upgrading I haven’t had it happen again.

  4. Janet said:

    on August 21, 2009 at 3:20 pm

    Just wanted to thank you for this article – it saved me from going nuts this week!

  5. �Anda raro el foro? - Page 5 - Comunidad GX said:

    on August 31, 2009 at 12:37 pm

    [...] ahi con lo q me dijste antes googlee y encontre la respuesta, esta corrupto el archivo de cookies How to recover a corrupted Firefox cookies.sqlite ghidinelli.com ahi esta, ahi te da la solucion DIFICIL para poder recuperar tus cookies y arreglar el problema, [...]

  6. barca26 said:

    on September 25, 2009 at 9:07 pm

    Thank You!

  7. Marvin said:

    on October 3, 2009 at 9:13 am

    “Orange is my favorite color”

    As a black man, I find this statement to be very offensive.

  8. Dan G. Switzer, II said:

    on October 3, 2009 at 1:46 pm

    I seriously hope Marvin is being sarcastic. I can’t even fathom how someone could take that statement to be racist.

  9. Brian said:

    on October 3, 2009 at 4:13 pm

    FWIW, I took it as a joke. I’m sure the “Orange people” though are stoked by my endorsement. ;-)

  10. Bryan Peters said:

    on October 13, 2009 at 5:33 am

    You’re a cookie lifesaver! Thanks for breaking down the steps – I had about 3k entries that I thought were lost.

{ RSS feed for comments on this post}