All the content on my site was gone. When I went to investigate, I found my error log was filled with the following error:
WordPress database error Table './database_name/prefix_posts' is marked as crashed and should be repaired for query SELECT YEAR(post_date) AS `year`, MONTH(post_date) AS `month`, count(ID) as posts FROM prefix_posts WHERE post_type = 'post' AND post_status = 'publish' GROUP BY YEAR(post_date), MONTH(post_date) ORDER BY post_date DESC made by require, require_once, include, do_action, call_user_func_array, flexx_after_content, get_sidebar, locate_template, load_template, require_once, dynamic_sidebar, call_user_func_array, WP_Widget->display_callback, WP_Widget_Archives->widget, wp_get_archives
A very scary looking error, but it was easy to fix.
My Preferred Repair Method
[user@server ~/public_html]$ mysql -u user -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 1120449 Server version: 5.1.48 MySQL Community Server (GPL) Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved. This software comes with ABSOLUTELY NO WARRANTY. This is free software, and you are welcome to modify and redistribute it under the GPL v2 license Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> connect database Connection id: 1120477 Current database: database mysql> select * from prefix_posts limit 1; ERROR 2006 (HY000): MySQL server has gone away No connection. Trying to reconnect... Connection id: 1120568 Current database: database ERROR 145 (HY000): Table './database/prefix_posts' is marked as crashed and should be repaired mysql> repair table prefix_posts; +-----------------------+--------+----------+----------+ | Table | Op | Msg_type | Msg_text | +-----------------------+--------+----------+----------+ | database.prefix_posts | repair | status | OK | +-----------------------+--------+----------+----------+ 1 row in set (3.56 sec) mysql> select * from prefix_posts limit 1; +----+-------------+---------------------+---------------------+--------------+------------+---------------+--------------+-------------+----------------+-------------+---------------+-----------+---------+--------+---------------------+---------------------+-----------------------+-------------+------------------------------------------------------------+------------+------------+----------------+---------------+ | ID | post_author | post_date | post_date_gmt | post_content | post_title | post_category | post_excerpt | post_status | comment_status | ping_status | post_password | post_name | to_ping | pinged | post_modified | post_modified_gmt | post_content_filtered | post_parent | guid | menu_order | post_type | post_mime_type | comment_count | +----+-------------+---------------------+---------------------+--------------+------------+---------------+--------------+-------------+----------------+-------------+---------------+-----------+---------+--------+---------------------+---------------------+-----------------------+-------------+------------------------------------------------------------+------------+------------+----------------+---------------+ | 12 | 8 | 2008-05-20 10:09:49 | 2008-05-20 15:09:49 | | 308image1 | 0 | | inherit | open | open | | 308image1 | | | 2008-05-20 10:09:49 | 2008-05-20 15:09:49 | | 0 | http://gaarai.com/wp-content/uploads/2008/05/308image1.gif | 0 | attachment | image/gif | 0 | +----+-------------+---------------------+---------------------+--------------+------------+---------------+--------------+-------------+----------------+-------------+---------------+-----------+---------+--------+---------------------+---------------------+-----------------------+-------------+------------------------------------------------------------+------------+------------+----------------+---------------+ 1 row in set (0.00 sec) mysql> exit Bye [user@server ~/public_html]$
For me, this was the easiest and quickest way to repair the table.
Repairing Tables with phpMyAdmin
For you, you might prefer to use phpMyAdmin. Fortunately, repairing a table with phpMyAdmin is easy.
- Log in to your phpMyAdmin or connect to it via your cPanel back-end.
- Select the database with the crashed table.
- Put a checkmark next to each crashed table.
- Select “Repair table” from the “With selected:” drop down at the bottom of the list.
- Let phpMyAdmin do its thing.
Did I help you?
I tried this and I get the same error, it doesn’t repair the table. I don’t have shell access to the server the hosts the database. Anything else I can try? 🙁
The key is to be able to run that query. If you can, you might try scripting up something that runs that repair query.
Good tip, I used the phpMyAdmin method and it fixed my database issue perfectly – Thanks
Glad to hear that it worked for you.
Nice tip , I have used it & repaired table successfully .
Thanks
Thanks – you’re a life saver! I freaked when I saw the message that my options table had crashed. Was able to fix it easily following your advice. Really appreciated.
Tony
[…] tomto článku jsem se dozvěděl jak tento problém […]
Great tip, this saved me a lot of time. As someone who had never touched MySQL before this was really helpful.
Thanks for the tip!
What can cause this issue and does it fix it for the long term?
You can find details about how table corruption can occur in these documents: Corrupted MyISAM Tables and Problems from Tables Not Being Closed Properly. If MySQL itself is crashing, this document has details on potential solutions: What to Do If MySQL Keeps Crashing.
As for whether or not
repair table
can prevent the issue from occurring again in the long-term, it can not. Therepair table
instruction tells MySQL to try to automatically repair the corrupted data, but it cannot do anything about the actual source of the corruption. The true source must be identified and fixed if the problems happen consistently.Thanks A LOT! It worked perfectly. Now I can login again to my wp admin.
Great! Thank you so much.
The phpmyadmin thing just worked!
[…] Fix “WordPress database error Table … is marked as crashed and should be repaired” :: Chris Je… […]
Thanks dear,. You solved my problem
Thank you! I used the cpanel method and it worked like magic.