How to fix corrupted tables in MySQL (2024)

MySQL is considered the best Open-source relational database management system (RDBMS), and it is trendy among developers from beginners to experts level.

However, the developers sometimes faced the problem of MySQL tables becoming corrupted. For example, corrupted tables mean that some error occurred in the table, and the data is unreadable now. If you forcefully read the data inside the corrupted table, it may crash the server.

Table Of Contents

  • Reasons for corrupted tables in MySQL
  • How to fix corrupted tables in MySQL
  • 1) Make a backup of the data:

Reasons for corrupted tables in MySQL

There are different reasons for the tables in MySQL to become corrupt. Some most common issues are:

  • There might be a software bug in the MySQL code

  • The MySQL server pause in the middle of the process

  • The hardware of the system fails

  • There may be an external program modifying a table, and at the same time, the server is also modifying it.

  • The computer suddenly stops working or shuts down

How to fix corrupted tables in MySQL

1) Make a backup of the data:

Before fixing the corrupted table, it is best to make a backup of the data directory, which will reduce the risk of losing the data.

To create a backup file, first, stop the MySQL service. The following code will help you to stop the MySQL service.

sudo systemcti stop mysql

The new data directory is now holding the data of the corrupted. If you are using the Ubuntu system, then the data will by default save as /var/lib/mysql:

  1. Investigate whether the table is corrupted or not:

Now we have to check whether the table is corrupted or not. To clear the doubt, use the command CHECK-TABE if the table uses MyISAM storage.

The following code is used to run the check-table statement:

After running this command, a statement will appear telling whether the table is corrupted or not. If the statement shows that the table is corrupted, follow the steps below.

  1. Repair the corrupted table:

The corrupted table can be easily repaired with the REPAIR-TABLE command if the table is using the MyISAM engine.

The following code is used to run the REPAIR_TABLE statement:

Here is a dummy result that will show you as output after running the above code:

But if the table is still corrupted, there are other suggested methods by MySQL.

How to fix the corrupted table in MySQL present in InnoDB

After version 5.5, MySQL uses InnoDB as a default storage engine for the new tables created in the MySQL database. The InnoDB has a plus point: the tables inside this storage engine do not get corrupted easily. However, the InnoDB gives an advantage to self-repair most of the issues just by restarting the server.

If the table gets corrupted, it is very easily be repaired.

Following are the reasons for the tables being corrupt under the InnoDB storage engine:

  1. The server of MySQL crashed after a reboot

  2. The primary platform has some bugs

  3. Hardware failure

When the table becomes corrupted, one cannot access read or access the data inside the table. And if you try so, the server of MySQL can be crashed

There are two methods to fix the corrupted InnoDB tables in MySQL

  1. Repair the corrupted InnoDB table manually:

Following are the steps that will help you repair the corrupted table manually.

Step 1: Restart the service

Restart the MySQL service and check whether you have access to the server or not. Follow the steps below to do so.

  1. Click Windows+R keys to open the run window.

  2. Type msc and then press ENTER key.

  3. There will be a SERVICES window that appears, right-click on MySQL services, and press RESTART.

Step 2: Force InnoDB recovery

This step will regain access to the corrupted tables through the MySQL database. Enable the Innodb_force_recovery option in MySQL configuration file my.cnf. Follow the steps:

  1. Open my.cnf file, in the [mysqld] section write:

  1. Save and close my.cnf file

  2. Restart the MySQL service again

Step 3: Drop the corrupted table

When you have access to the corrupted table, drop the data of that table in a new file using the following command.

If you want to insert multiple tables in the above code, use whitespace between the names of the tables.

Now put the corrupted table of the database using the following command.

Step 4: Restore the table

In this step, we will restore the newly created file in which we dropped the data of the corrupted table using the following command.

Step 5: Restart MySQL in normal mode

Now that we repaired the corrupted table stop the MySQL service and disable Innodb_force_recovery using the following code again in the [mysqld] section.

Restart the MySQL services in the normal mode.

Note: If you have access to the MySQL server, skip the first two steps mentioned above. Also, skip the last step and stop and restart the server.

Conclusion

Corruption in the MySQL table can corrupt and make data within it unreadable. This kind of corruption, if not resolved within time, may result in server crashes, unexpected downtime, and loss of data. Manual processes to repair tables can be tiresome and may lose some data, making them unreliable.

To repair tables on the InnoDB storage engine and restore it to its original functioning state, you can use software that repairs MySQL databases called Stellar Repair for MySQL. This software works on both Windows operating systems and Linux-based computers, and not only can it repair InnoDB tables, but MyISAM tables as well. Use this file repair program to fix problems with your database.

How to fix corrupted tables in MySQL (2024)
Top Articles
13 Best Stocks To Buy and Hold Forever
Trigger Words That Will Cost You the Job - Snelling
#ridwork guides | fountainpenguin
Kevin Cox Picks
Busted Newspaper Zapata Tx
Ghosted Imdb Parents Guide
Poplar | Genus, Description, Major Species, & Facts
Wfin Local News
Truist Drive Through Hours
Weather Annapolis 10 Day
Missing 2023 Showtimes Near Lucas Cinemas Albertville
Jasmine Put A Ring On It Age
C Spire Express Pay
The most iconic acting lineages in cinema history
Sony E 18-200mm F3.5-6.3 OSS LE Review
WEB.DE Apps zum mailen auf dem SmartPhone, für Ihren Browser und Computer.
Jellyfin Ps5
Craigslistjaxfl
Tyler Sis University City
Busted Campbell County
Blue Rain Lubbock
Brazos Valley Busted Newspaper
Mybiglots Net Associates
Vernon Dursley To Harry Potter Nyt Crossword
The best brunch spots in Berlin
TeamNet | Agilio Software
Danielle Ranslow Obituary
Airline Reception Meaning
4Oxfun
Top 20 scariest Roblox games
Alternatieven - Acteamo - WebCatalog
Metro By T Mobile Sign In
Autotrader Bmw X5
Mg Char Grill
Reli Stocktwits
Blue Beetle Movie Tickets and Showtimes Near Me | Regal
دانلود سریال خاندان اژدها دیجی موویز
Craigslist Lakeside Az
Metro Pcs Forest City Iowa
Discover Wisconsin Season 16
Wasmo Link Telegram
Sofia With An F Mugshot
Coroner Photos Timothy Treadwell
Courses In Touch
9:00 A.m. Cdt
Best Suv In 2010
Menu Forest Lake – The Grillium Restaurant
Best Restaurant In Glendale Az
Richard Mccroskey Crime Scene Photos
Roller Znen ZN50QT-E
Philasd Zimbra
Latest Posts
Article information

Author: Lidia Grady

Last Updated:

Views: 5799

Rating: 4.4 / 5 (65 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Lidia Grady

Birthday: 1992-01-22

Address: Suite 493 356 Dale Fall, New Wanda, RI 52485

Phone: +29914464387516

Job: Customer Engineer

Hobby: Cryptography, Writing, Dowsing, Stand-up comedy, Calligraphy, Web surfing, Ghost hunting

Introduction: My name is Lidia Grady, I am a thankful, fine, glamorous, lucky, lively, pleasant, shiny person who loves writing and wants to share my knowledge and understanding with you.