🛠️
Hosting

Corrupted MySQL Table: How to Check and Repair It

16.11.2026
← All articles

One day the site stops loading, or only some pages fail, and the log says a table is corrupted and needs repair. MySQL tables rarely break, but when they do, working in the right order matters: a wrong step can lose data, while the right sequence often fixes the table in minutes.

Why tables get corrupted

Most corruption happens when MySQL stops unexpectedly mid-write: a power cut, the server running out of memory and the system killing MySQL, or a full disk or hosting quota. Faulty disks and file system errors are rarer causes. The storage engine matters a lot. Old MyISAM tables have no transaction log, so an interrupted write easily damages the table or its index file. InnoDB writes changes to a log first and recovers automatically on restart, making it far more robust, though serious disk failures can still hurt it.

Signs of corruption

Table './shop_db/sessions' is marked as crashed and should be repaired
Incorrect key file for table 'sessions'; try to repair it

Those are typical MyISAM messages. InnoDB problems look different: MySQL may not start, may restart repeatedly, or may log corrupted page errors. Check MySQL's own error log first: it usually names the table or file involved, which tells you whether you are dealing with a single damaged table or a wider problem with the data directory.

Step one: back up

Copy the current state before any repair, even if it is broken, because repair can discard damaged rows, and you may need the original copy later to recover them. A plain dump is enough while the database still runs; if MySQL will not start, copy the data directory with the service stopped:

mysqldump -u shop_user -p shop_db > shop_db_before_repair.sql

# if MySQL will not start (VPS, as root):
sudo systemctl stop mysql
sudo cp -a /var/lib/mysql /var/lib/mysql_backup_20261104

Checking tables

CHECK TABLE sessions, orders;

mysqlcheck -u shop_user -p --check shop_db

OK in Msg_text means healthy; error or Corrupt means repair is needed. phpMyAdmin also offers check and repair actions for selected tables.

Repairing MyISAM

REPAIR TABLE sessions;

mysqlcheck -u shop_user -p --auto-repair --check shop_db

Afterwards, consider converting the table with ALTER TABLE sessions ENGINE=InnoDB; so it does not happen again. Run it during quiet hours on large tables.

Dealing with InnoDB

InnoDB does not support REPAIR TABLE. For mild cases, rebuilding with ALTER TABLE orders ENGINE=InnoDB; helps. If MySQL will not start because of corrupted InnoDB pages, use recovery mode on your VPS:

# /etc/mysql/my.cnf or /etc/my.cnf, [mysqld] section
[mysqld]
innodb_force_recovery = 1

Start at 1 and raise it step by step only if MySQL still fails, since higher values are riskier and from 4 upward can permanently damage data files. Once running, dump the data, recreate the database, import the dump, remove the setting and restart normally.

Example: a news site hits its quota

A regional news site in Fergana, misol.uz, filled its hosting quota with backup archives while still writing to a MyISAM sessions table. By morning visitors saw a database error, and the log reported a crashed sessions table. The team freed disk space first, since repair fails without it, took a dump, checked the table in phpMyAdmin and ran REPAIR TABLE. The site was back within minutes, and all MyISAM tables were then converted to InnoDB. On sayt.uz hosting, if you cannot repair it yourself, open a ticket in the cabinet with the table name.

Preventing it

Use InnoDB, keep free disk space, take regular backups, watch quota warnings and store backup archives outside the site folder. Then an unexpected crash will not put your data at risk, and a ready copy will always be at hand.

Related articles

📦 Hosting Plan Terms Explained: Disk, Inodes, CPU, RAM and Processes 🔑 Enabling SSH on your hosting and connecting with a key 🧩 Garbled characters on your site: causes and fixes for broken encoding 🛡️ Is your hosting backup enough? The 3-2-1 rule in practice
🌐 Language
🇺🇿 O'zbek 🇺🇿 Ўзбек 🇷🇺 Русский 🇬🇧 English ✓