I’ve seen a lot of entries around the Web about people “loosing” their categories after restoring a backup [note #1 and #2]. Well, I somehow encountered something similar and this is how I solved it.
I will keep this short — as I do most of the time.
For starters, check your web server logs for the following entry:
[Fri Jan 18 20:18:20 2013] [error] [client x.x.x.x] WordPress database error Can’t create/write to file ‘/mysqltmp/#sql_170c [snipped]
Does that look familiar?
Well, first of all make sure /mysqltmp exists and that it has the right permissions and ownership. If it does not exist, create the directory along with the necessaries (i.e correct permissions and ownership). Easy.
Restart your web server, and voilà! Everything should work fine again. Usually this is merely a permissions issue.