We use cookies on this website. By using this site, you agree that we may store and access cookies on your device Read More Got it!
MySQL Repair 4 minute read

How to Repair MySQL Database Table Without Downtime

Priyanka Chauhan
Written By
Priyanka Chauhan
Kuljeet Singh
Approved By
Kuljeet Singh
stellar calander
Updated on
January 31st, 2023

Summary: Table corruption is one of the key reasons for MySQL database corruption and downtime. It takes considerable time to repair MySQL database tables, which prolongs business downtime and causes major inconvenience to the users.

Free Download for Windows

Contents

  • Reasons for MySQL Database Table Corruption
  • MySQL Table Corruption Prevention tips
  • Methods to repair corrupt MySQL database tables Without Downtime
  • Conclusion

Thankfully, there are several simple and effective methods to fix corrupted MySQL database, without downtime. Let us explore some of these methods.

MySQL is an open-source RDBMS, which runs on all major operating systems like Windows, UNIX, and Linux. It is mostly used in web applications and online businesses. Many leading platforms like Facebook, YouTube, Twitter, and several other organizations use MySQL database.

But sometimes MySQL database gets corrupted due to underlying database table corruption. This can cause a lot of issues for businesses. Performing MySQL database table repair is an arduous task which needs time and efforts.

However, through this article we’re exploring some easy ways to repair MySQL database tables and bring the database back online.

Let us start with the reasons for MySQL table corruption.

Reasons for MySQL Database Table Corruption

MySQL database tables can become corrupted due to one or more of the following reasons:

  1. Due to problems in the underlying platform used by MySQL to store and retrieve data. It includes controllers, drivers, disk subsystem, firmware, and communication channels.
  2. Due to abrupt restart or crash, which can cause the database tables to remain stuck in the middle of the transaction.
  3. Due to program files missing from MySQL directory.
  4. Use of unverified and incompatible third party software to access the MySQL database
  5. Use of “killall -9 MySQLd” commands to shut down the server, which can also kill the ongoing MySQL processes
  6. Due to virus or malware attack on the system

In addition to understanding the above reasons for MySQL table corruption, it is also important to practice preventive measures to avoid database corruption.

MySQL Table Corruption Prevention tips

Here are some ways to prevent corruption of MySQL database tables:

  1. It is always advised to test MySQL kernel by using MySQLid command. This command runs in the background and starts the MySQL server on your machine.
  2. Never use a computer without UPS support. A power outage may interrupt your ongoing operation resulting in database table corruption.
  3. Always keep an up-to-date backup of your MySQL database. It is recommended to take the database backup at least once in a week.
  4. Use an anti-virus on your machine to stop viruses and malware from corrupting your database tables.

The above listed tips will help you protect database tables from corruption. In case MySQL database tables still get corrupted, you can use the following methods to repair MySQL database tables without downtime.

Methods to repair corrupt MySQL database tables Without Downtime

Method 1: Repair the table online

Repairing the corrupted database table online can save your users from unwanted database downtime. You can follow the below mentioned steps:

  • First, you need to login to the MySQL server with the help of SSH (Secure Shell).
  • Go to the command line and type in the below mentioned command providing your actual username and without using brackets

mysql -u [username] -p

  • Now provide the password.
  • Once you are logged in, type the following command providing your actual database name without using brackets

use [databasename];

  • Now type the following command to see a list of all the tables present in your database

show tables;

  • One thing you need to note here is that there is no way to repair multiple tables at once using a single command. Hence, you need to use the following commands for every table which is corrupted.
  • To check the table for errors, type this command providing your actual table name without using brackets

check table [yourtablename];

  • Now to perform the repair procedure, type this command providing your actual table name without using brackets

repair table [yourtablename];

  • Enter quit in the command prompt to exit and the table will now be repaired automatically.

Method 2: Repair the table offline

In this method, instead of repairing the table online, you can easily move the files related to the table in another folder and then perform the repair process there.

For instance, in order to repair a table named database.mytable, you can use the commands shown below from the folder /var/lib/mysql:

REPAIR_OPTION=”-r”
DB_NAME=mydb
TABLE_NAME=mytable
FRM=${TABLE_NAME}.frm
MYD=${TABLE_NAME}.MYD
MYI=${TABLE_NAME}.MYI
cd /var/lib/MySQL/${DB_NAME}
mv ${FRM} ..
mv ${MYD} ..
mv ${MYI} ..
cd ..
myisamchk -${REPAIR_OPTION} ${MYD}
myisamchk -${REPAIR_OPTION} ${MYI}
mv ${FRM} /var/lib/MySQL/${DB_NAME}
mv ${MYD} /var/lib/MySQL/${DB_NAME}
mv ${MYI} /var/lib/MySQL/${DB_NAME}

If you find that –r is not working in the “REPAIR_OPTION” command you can run the same command using the –o option.

Method 3: Repairing MyISAM tables with myisamchk

Please note that this method will only work for the tables which are using MyISAM storage engine. You can follow the below steps to repair the corrupted database table.

  • In an SSH prompt, type the command: service mysql stop
  • Now type the command: cd /var/lib/mysql
  • Now you have to change the directory location to where the database is actually located. For example, if the name of the database is mydatabase, then type the following command:

cd mydatabase

  • Now type this command providing your actual table name without using brackets

myisamchk [TABLE]

  • Now to repair the table, type the following command providing your actual table name without using brackets

myisamchk –recover [TABLE]

  • Now restart the MySQL server using the following command

service mysql start

  • You can check the repaired tables and they should work fine.

Method 4: Repair the corrupted database with Stellar Repair for MySQL

If none of the above mentioned methods works to repair the tables in question, switch your efforts to a method which will work for sure. Download Stellar Repair for MySQL and fix your database. This advanced MySQL repair software provides an effective solution to fix MySQL database corruption, and restores all inaccessible objects like primary keys, triggers, views, etc. quickly. The tool repairs InnoDB and MyISAM tables, recovers table properties, and performs many other advanced operations.

Free Download for Windows

Conclusion

Don’t let your users suffer from downtime due to critical MySQL database table corruption. Try out one of the manual methods mentioned above, to fix database table swiftly. And if you find the manual methods too difficult or not working, try out Stellar Repair for MySQL to perform MySQL database table repair.

Do let us know your views and queries via posting the comments below.

About The Author

Priyanka

Priyanka is a technology expert working for key technology domains that revolve around Data Recovery and related software's. She got expertise on related subjects like SQL Database, Access Database, QuickBooks, and Microsoft Excel. Loves to write on different technology and data recovery subjects on regular basis. Technology freak who always found exploring neo-tech subjects, when not writing, research is something that keeps her going in life.

Best Selling Products

Stellar Data Recovery Professional for Windows

Stellar Data Recovery Professional for Windows

Stellar Data Recovery has the right Windows Recovery tool for all your data recovery

Read More
Stellar Data Recovery Professional for Mac

Stellar Data Recovery Professional for Mac

Stellar Data Recovery for Mac program performs safe..

 

Read More
Stellar Photo Recovery

Stellar Photo Recovery

A comprehensive photo recovery software to restore photos, music & video files

 

Read More
Stellar Repair for Video

Stellar Repair for Video

Powerful video repair tool for repairing corrupt or damaged MOV and other video files

 

Read More

6 comments

  1. Niloma D says:
    February 25, 2020 at 11:03 am

    I found some of my table’s data is missing after using 2nd method i.e. Repair the table offline. How can I recover whole data of tables?

    Reply
  2. Tony Walker says:
    February 20, 2020 at 11:49 am

    I want to know our company database has more than 100 tables, So can I repair it with Stellar Repair for Mysql?

    Reply
  3. Lopa gomej says:
    October 16, 2019 at 5:14 am

    What is the average downtime while executing this command over live production database?

    Reply
    1. Eric Simson says:
      October 16, 2019 at 9:37 am

      It depends on the volume of the data.

      Reply
  4. Nancy I. Ward says:
    July 28, 2019 at 11:51 am

    Hi,

    Is software work on the original mysql database file?

    Reply
    1. Eric Simson says:
      July 31, 2019 at 10:08 am

      Don’t worry!

      Our any software doesn’t harm the integrity of the original file. We care your data like an asset.

      Reply

Leave a comment Cancel reply

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

Image Captcha
Refresh Image Captcha

Enter Captcha Here :

Table of Contents    arrow

  1. Reasons for MySQL Database Table Corruption
  2. MySQL Table Corruption Prevention tips
  3. Methods to repair corrupt MySQL database tables Without Downtime
  4. Conclusion

Categories

offer banner

Related Posts

related post
MySQL Repair

[Fixed] MySQL innodb_force_recovery is Not Working Properly

Stellar Author Charanjeet Kaur January 21, 2022 Read More
related post
MySQL Repair

How to Repair MySQL Database using phpMyAdmin?

Stellar Author Charanjeet Kaur November 11, 2021 Read More
related post
MySQL Repair

How to Repair MySQL Tables Using Mysqlcheck

Stellar Author Charanjeet Kaur July 17, 2021 Read More

Free Trial for 60 Days

Technology You Can Trust A Brand Present Across The Globe

  • tuv1
  • tuv2
  • Nist
  • hipa

Stellar Official Website

Stellar Data Recovery Inc.
48 Bridge Street Metuchen,
New Jersey 08840,
United States

ALSO AVAILABLE AT

ALSO AVAILABLE AT

About

  • About us
  • Career
  • ISMS Policy
  • Privacy Policy
  • Terms of Use
  • License Policy
  • Refund Policy
  • End User License Agreement

RESOURCES

  • Blog
  • Articles
  • Product Videos
  • Knowledge Base
  • Case Studies
  • Whitepapers
  • Software Catalog

NEWS & EVENTS

  • News
  • Events

PARTNERS

  • Affiliates
  • Resellers
  • Distributors

Useful Links

  • Contact Us
  • Support
  • Special Offers
  • Student Discounts
  • Awards & Reviews
  • Downloads
  • Store
  • Sitemap

Stellar & Stellar Data Recovery are Registered Trademarks of Stellar Information Technology Pvt. Ltd. © Copyright 2023 Stellar Information Technology Pvt. Ltd. All Trademarks Acknowledged.

Follow Us Facebook Twitter Linkedin Youtube

  • Notron
  • dcma