How to Repair Tables Marked Bad or Corrupt in MySQL

For more than a year we used the Counterizer plugin for WordPress and thus keep statistics of the blog and its readers, this plugin we deactivated a few days ago since (among other things) it saved more than 600MBs of data in the database.

It happens that (before deactivating the plugin and cleaning the DB) I tried to dump the database, that is, export it to .SQL and thus download it and in the hosting terminal I got the following error:

mysqldump: Got error: 144: Table './dl_database/Counterize_Referers' is marked as crashed and last (automatic?) repair failed when using LOCK TABLES

So, the dump was not executed and well… just the idea that the DesdeLinux DB had some problem made my hair stand on end 

Doing a little research on the web I was able to learn how to solve this problem, apparently it is NOT that the database has problems exactly, simply that a table is marked as 'with problems', fortunately this is very simple to fix.

First let's access the MySQL server:

mysql -u root -p

We press [Enter] and it will ask for the MySQL root password, we put it and press [Enter] again.

This command is in case the MySQL server is installed on the same computer, if you want to connect remotely to another MySQL server you must add the following to the line: -h IP-OF-SERVER

Once inside MySQL we will tell you which database to use, for example the problem according to the error above is in the table Counterize_Referers from the database  dl_database, so that:

use database dl_database;

And now to repair the table base:

repair table Counterize_Referers;

Note that at the end of these lines there is a semicolon —– »  ;

Once the previous command has been executed, everything should have returned to normal, at least in my case it has been like this on more than one occasion 

Then it only remains to rerun the instruction to dump the database and voila, nothing more.

Anyway, I'm doing this more as a memo to myself than anything else, as the same thing has happened to me twice already and I don't want to forget the instructions to save my day 

Greetings and I hope it is helpful to someone else.


Add as preferred source