Check tables of a MySQL database and repair corrupt

I am one of those who likes to be aware of the servers that I manage, although they are highly stable, it never hurts to always keep an eye on them, as the saying goes:

The eye of the master fattens the horse

From time to time it is good to do several checks on the server and its services, in this case I will talk about how to check the tables of a database and in case one is corrupt, how to repair it.

Check the tables of a MySQL DB

As for everything (or almost everything), there is a fairly simple command that allows us to check all the tables in a MySQL database:

mysqlcheck --check BASE_DE_DATOS --user="USUARIO" --password="PASSWORD"

For example, suppose I have a database called: project thesis

My MySQL administrator user is: root

And the password of that user is: misuperpassword

So the line would be:

mysqlcheck --check proyectotesis --user="root" --password="misuperpassword"

It would show something like:

dfirefoxos.wp_commentmeta OK dfirefoxos.wp_comments OK dfirefoxos.wp_links OK dfirefoxos.wp_options OK dfirefoxos.wp_postmeta OK dfirefoxos.wp_posts OK dfirefoxos.wp_term_relationships OK dfirefoxos.wwwp_term_firefox OK dfirefoxos.wp_termtermsfirefoxfirefox_wp_term_fireosfirefox_wpfoxosponomy_term_postsfirefoxfirefox_term_relationships OK_wpfoxosfirefox_term_relationshipsfirefox OK_wp_term_fireosfirefox_wpfoxospfoxonwp_term_

In other words, all the tables are right now.

How to repair a table in case it appears as corrupt?

I already made a post explaining this in detail: How to Repair Tables Marked Bad or Corrupt in MySQL

However, I will leave the steps here.

1. First we must enter MySQL through terminal:

mysql -u root -p

It will ask us for the root password, we put it and press [Enter].

2. Then we must indicate which database we will use, that is, which is the database that has the corrupted table. Following the example at the beginning, let's say the database is: project thesis

use proyectotesis;

Every semicolon is VERY important; put at the end.

And now we tell it to repair the corrupt table, for example let's say the table is called: public_information

Would:

repair table public_information;

And voila, this should be enough to repair it in most cases.

I hope it is useful to you ... and that you never have corrupt tables 😀


Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Alberto Cardona said

    Hello, very good contribution, the previous one to fix the error too 😀

    One question, I currently use mariadb, do you know if the book (guide) «sql99» is in Spanish?
    o Some good sql99 guide, to know the complete syntax about the DDL since it is not complete in the MariaDB guide.

    regards

    1.    KZKG ^ Gaara said

      Hello,

      No idea friend, I don't know what book it is, sorry.

  2.   eliotime3000 said

    Perfect, so I can repair the error that does not allow me to apply the URL Alias ​​of yore that WordPress does not give me after migrating my site from Apache to NGINX.

  3.   koratsuki said

    Also, with phpMyAdmin you can, after you log in, select the database, mark all the tables and execute the option «Repair tables» from the drop-down menu ...
    Salu2 and I hope it serves you 😀

    1.    KZKG ^ Gaara said

      Nice, I didn't know that one!

    2.    elav said

      Repair and Optimize .. 😀

      1.    eliotime3000 said

        The same, although in phpmyadmin it has the power to handle it at the end of commands in case one does not get used to so much IDE.