In this article, you will learn how to repair MySQL Tables.

There are two ways to repair the crashed MySQL tables.

  1. Repair MySQL Tables with SSH Method
  2. Repairing MySQL Tables with phpMyAdmin

But first of all, you need to take a backup.

Backup Your Database

To take the backup, follow the instructions:

  • Login to your server using SSH
  • Stop the MySQL server using the commands

For Debian and Ubuntu:

service mysql stop

For CentOS and Fedora

service mysqld stop

Run this command to make backup

cp -rfv /var/lib/mysql /var/lib/mysql$(date +%s)

This command copies all of the files from all of your databases to a directory name based on the current time.

Restart the MySQL server using the command

For Debian and Ubuntu

service mysql start

For CentOS and Fedora

service mysqld start

After making the backup, you should know what to expect when you run the repair.

How long it takes to repair a MySQL table?

Time depends on the size of the table.

  • A KB table would be repaired in a few seconds.
  • If the size of the table is in MB, it may take up to minutes.
  • GB size tables might take hours.

The larger the size, the more time it will take. If the table size is huge, it may even take days or weeks.

The time it takes in repairing also depends on available Ram and processing power.

You know what to expect, so let’s begin:

There are two ways to repair MySQL Tables:

  • SSH Method
  • phpMyAdmin Method

Repair MySQL Tables with SSH Method

To repair MySQL tables, follow the instructions:

  1. Login to your MySQL server using SSH
  2. Run this command
mysqlcheck -r [database name]

Replace the database name with your database name.

NOTE: mysqlcheck is the command to check the mysql, while -r means to begin the table repairing.

Repair MySQL Tables with phpMyAdmin Method

Follow the instructions to repair MySQL table via phpMyAdmin.

  • Login to your cPanel.
  • Look for the phpMyAdmin under database section
database php
  • In the left pane, select the database that you needs to repair
How to Repair MySQL Tables with SSH?
  • In the right pane, select the database tables
Right Panel
  • From the list box below, select repair.
repair png
  • After fixing the MySQL table, phpMyAdmin will inform you.
Repair Done

Why the MySQL Table Crash?

The number one cause of crashing of MySQL Tables is running out of disk space

If you are working with a huge amount of data, keep checking the Disk storage.

Other causes could be:

  • Operating System problems
  • Power Failures
  • Hardware Problems
  • Abrupt Termination of Program
  • Other Software meddling with the servers

What is MySQL and Why is it Used?

SQL means Structured Query language. MySQL is open-source software under the terms of GNU General Public License. It is compatible with the majority of operating systems, including, CentOS, Ubuntu, and Windows.

There are many Database Management Software.

MySQL is the best option for relational database management. Oracle Corporation handles its distribution and support. 

Crashing of MySQL tables is inevitable. But if you know how to repair MySQL tables, there is no need to panic. 

If you are a client of ServerGuy, just contact us. Our 24/7 team will help you in resolving the issue.

We hope you know how to fix crashed MySQL tables with SSH and phpMyAdmin now. 

Still, any doubt, leave a comment.

Posted by Editor