WordPress database error: [Incorrect key file for table './mydb/wp_posts.MYI'; try to repair it]
Googling the error pushed me toward the myisamchk tool. So I went into MySQL’s data dir on my server as root and tried to run a repair on my files:
myisamchk *.MYI
But I was greeted with this:
myisamchk: unknown variable ’socket=/var/db/mysql/mysql.sock’
I wasn’t feeding it any variables, so I figured it was pulling it from some default config file. First I tried overwriting the value in ~/.my.cnf but that didn’t do anything. After poking around in the MySQL manual I found the --no-defaults option, which should suppress default option file reading for most MySQL clients that consume option variables. Well that worked.
My final command that fixed the corrupt indexes was:
myisamchk --no-defaults --backup --recover *.MYI
Hopefully this saves someone additional time and frustration.

