Month: November 2017

Repairing WordPress MySql Table corruption

We suffered a SAN outage which caused one of our wordpress servers to come back up with a corrupted table.

 

In the wordpress logs this presented as:

[error][client IP] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: http://example.com/

Not exactly clear error message.  Digging into the mysqld log was more illustrative of the problem:

[ERROR] /usr/libexec/mysqld: Table './db/wp_options' is marked as crashed and should be repaired

(The database name was changed to protect the innocent).

With the above error, I now understood the problem and how to approach fixing it.

# mysql -u root -p
Enter password:
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

mysql> connect db;

Connection id: 2244
Current database: db

mysql> select * from wp_options limit 1;
ERROR 145 (HY000): Table ‘./db/wp_options’ is marked as crashed and should be repaired
mysql> repair table wp_options;
+—————————–+——–+———-+——————————————————-+
| Table | Op | Msg_type | Msg_text |
+—————————–+——–+———-+——————————————————-+
| db.wp_options | repair | info | Wrong block with wrong total length starting at 52540 |
| db.wp_options | repair | warning | Number of rows changed from 314 to 313 |
| db.wp_options | repair | status | OK |
+—————————–+——–+———-+——————————————————-+
3 rows in set (0.05 sec)

mysql> select * from wp_options limit 1;
+———–+————-+————————–+———-+
| option_id | option_name | option_value | autoload |
+———–+————-+————————–+———-+
| 1 | siteurl | https://example.com | yes |
+———–+————-+————————–+———-+
1 row in set (0.01 sec)

mysql> exit
Bye

And that quickly the site was back up and functional, no restart required!

Hope that helps someone or me in the future.