Database repair failed, Problems with wp_comments and wp_options
-
Hey! I’ve had a wordpress site up and running for months, just updating the theme and wordpress software as well as plugins. After the last round of updates (1-2 weeks ago), everything was fine. Today, I want to work on the site and get “Error establishing a database connection”.
Added the database repair code to the wp_config.php and tried repairing. These two error messages remained:
wp_comments: Incorrect file format ‘wp_comments’
wp_options: Incorrect key file for table ‘wp_options’; try to repair itAlso updated PHP to 7.0, without any change. Is there a way to recover this data or repair the tables?
Thanks!
Ulrich
-
Hello Ulrich!
I am not sure if the PHP version change is connected with the database issues. Here is an article that describes what to do if WordPress repair did not work as it should (look for the “What if the above method doesnβt work” heading):
https://www.maketecheasier.com/fix-corrupted-wordpress-database-2/A word of caution, you should definitely make a backup of your database before tinkering in phpMyAdmin π
Regarding recovering data, it depends on how is your website hosted. If you are with a hosting company, it is possible they have some backup of your database. It can vary how often they make backups, but it is definitely a start π In any way, I would suggest, that you make a backup of your current, damaged database too, in case the database from the backup does not work as it should. Since you mentioned you were doing some updates recently, it is possible you will have to do some things again, but it is a start π
Let me know how it goes, or if you have any questions, just feel free to shoot a reply here.
Cheers,
BalintHi Balint,
thanks for your fast reply. The PHP version change was something I tried *after* the problems occurred. The last updates I did, after those everything was working. I don’t know what happened inbetween then and now.
An update of the database is just a simple export? Or is there more I have to do?
Since it’s just the wp_comments and wp_options that are corrupted, can I import my backup database with the exception of these two tables, to recover all data except these two? I don’t have any comments and the options won’t be too much trouble to insert again, I guess.
Thanks,
UlrichAn update of the database is just a simple export?
I am not entirely sure what are you referring with this, could you please explain?
Backing up a database IS basically an export in phpMyAdmin, or there are a ton of WordPress plugins that can do that for you, I usually use BackWpUp, or UpdraftPlus.
I don’t see why would be good to leave out the two corrupted databases, since those are giving you issues. Yes, it is possible you will lose some comments, but the point is (at least in my understanding π ) is to get up and running as soon as possible.
We could turn this the other way around, you could only import those two tables from the backup, but there are a ton of interconnected data between database tables, and it is especially true with wp_options. (I am referring to foreign keys in the database if that means something to you, if not, no worries), so by importing the full backup, basically you “revert” the whole database to a specific point in time.I am sadly not too familiar how MySQL works under the hood in these situations where there is a database corruption, is it only in the data structure or is it a “physical” damage on the server’s hard drive, so for the first step, I would advise to drop the tables from the database before you import the backup. If after that you still getting this error, we can investigate further.
Balint
Hi Balint,
I was working for a few days, so here’s my late answer. I don’t have access to the WordPress admin environment due to this problem. So I can only backup the database from phpMyAdmin. That’s why I was asking if backup just means exporting the database. Unfortunately, the hosting company can only do a recovery using a backup for 100 β¬, too much for such a “simple” problem, if it really means I can recover everything else aside from these tables.
Once I’ve done the backup, what’s the best way to reinstall? Do I reinstall all of wordpress? Or just the database? It would be good to keep as much of the data that’s okay, so I’m thinking I don’t need to delete the pages of my website, do I?
This is all a bit confusing. I come from programming straight-up HTML, all by myself, no WYSIWYG, and I always knew the exact structure of my site. With wordpress, there’s a lot of invisible stuff going on for me.
Regards,
UlrichHello Ulrich, no worries about the slow reply π
Wow, 100 dollars is A LOT! I am guessing they wont give you the backup and allow you to do the recovery yourself, right? I am not an affiliate for any hosting company, but my honest oppinion is that you should change your host… That is a big red flag…
Yes, basically backing up from phpMyAdmin is just simply making an export, with a bit of caveat that you have to watch out for.
First, when you make an export, you have to watch out that you are exporting the whole database, not just a table (been there, done that, and regretted my mistake a lot π ). The easiest way is to check on the top of the Export page, does it say Exporting rows from xyz table or Exporting tables from xyz database, you need the latter one π
The other part is to set up, or should I say, to specifically set how phpMyAdmin will create the backup. There are two options. The first one is to backup only the information, the contents of the database, and the other is to backup the database structure and the data, meaning the backup file will contain instructions on how to recreate the database tables (CREATE TABLE commands if you are familiar with mySQL).
I think there is no general solution, so I suggest we try 2 things. First, let’s try just creating a new database, import the backup you have just made, and modify WordPress to use that database instead of the old one.
If that does not work, then the other possible solution is to reinstall WordPress and try to import the data from the backup database, it is the harder way, and it is almost sure you will lose some comments. The two tables malfunctioning, contain the comments made by visitors on your site, and the WordPress settings, that is why the site is not working, the settings info is necessary for WordPress to function properly.
Just a question, how big is your database?
Sorry for this becoming too long, bear with me π
Here is how to export the database for creating a new one for WordPress, without reinstalling the site. I am sorry that I cannot show it with an actual WordPress database, but you should be able to follow along nevertheless.
When you are at the Export page in phpMyAdmin, select Export Method: Custom (like on this screenshot)
Scroll down to the Object creation options part. (Screenshot)
Make sure you check Disable Foreign Key Checks in the upper part like on the screenshot, and make sure your settings match exactly in the lower part (Object creation options). When you have done that, make the export.
When you have done that, you should create a new database in PhpMyAdmin. Here is a video how to do it in phpMyAdmin, or here is an article how to do it from cPanel.
Make sure you write down somewhere the database name of the database you have just created, and the database username and password, if you needed to create one.
After you have created the new database, go to Import in phpMyAdmin, and import what you have previously Exported, your backup from the corrupted database.
When it is finished, you have to edit the wp-config.php file, it is beside the wp-contents folder, probably right in public_html or www. (Screenshot). You will need to edit it with a code editor, and change some things.
You will need to change a couple of things, here is the part we are interested in: Screenshot, of course your file will have the settings for your site.
you will have to change the database name (DB_NAME), type in the new one you have just created. If you have asked for a new database username and password when you have created the new database, you will have to change the DB_USER and DB_PASS values respectively. If you did not have to create a new user, then don’t change those two values. DB_HOST will remain the same. When you have made the changes, save the file and check your site.I have tried to describe it as good as I can, if you have any questions, just feel free to ask. And let me know how it goes.
Balint
Hi Balint,
first off: don’t be sorry for writing too much! I am so thankful you are taking all this time for me!
My site is more or less back up and running, thanks to you! What I did was this: I exported the database, leaving out the corrupt tables. I then imported them into a new database and put the new database in the wp_config.php file. Still, I got the same error message, since the database was now missing two tables. No way to create these easily, so I cleared the database again and went to http://www.domain.com/wp-admin/, which prompted WordPress to start a fresh install of the database. Now I had a blank database with the correctly formatted tables and imported my backup into that (everything intact and just the two tables empty). Now I have to work on the options and settings to get the site looking as it was before, but I’m nearly there.
The database was small, by the way, 2 MB. It’s a fairly new site and I haven’t done much work on it yet. I don’t believe I had a single comment, so losing those was no problem at all. The settings won’t be much work, if I can remember approximately what I did last time.
So, for now, it’s working again. Thanks a million for all your help!
You are welcome! I am glad we could solve this issue together.
Have a nice day!
Balint
Thanks, you too!
The topic ‘Database repair failed, Problems with wp_comments and wp_options’ is closed to new replies.