Databases & NoSQL

Ultimate Guide to Checking, Repairing, and Optimizing MySQL/MariaDB Databases for Peak Performance

By the Domain India teamPublished 9 min read
Knowledge base article
Contents (9 sections)

MySQL and MariaDB databases need a little care: an occasional check for damaged tables, a repair when something breaks, and sensible settings so queries stay fast. This guide covers how to check, repair and optimise tables safely, how InnoDB crash recovery works, and which tuning settings still matter in 2026. It has two paths: one for shared hosting through phpMyAdmin, and one for your own VPS or server with full command-line access.

Key takeaways

Back up before any repair. On shared hosting, use phpMyAdmin (or cPanel's MySQL Databases page) to check and repair tables; you cannot change server settings. On your own server, use mysqlcheck (or mariadb-check) for MyISAM checks and repairs. InnoDB repairs itself after most crashes; for real corruption, start with innodb_force_recovery = 1, dump your data and rebuild. Never delete ibdata1 or the redo logs. For speed, fix slow queries and indexes first, then size innodb_buffer_pool_size to your RAM.

Back up first, every time

A repair rewrites table files. If it goes wrong, the backup is your only way back. On shared hosting, export the database in phpMyAdmin (how to back up a MySQL database using phpMyAdmin). On a server, run mysqldump --single-transaction before you touch anything.

1. MyISAM and InnoDB: why it matters

QuestionInnoDBMyISAM
Default todayYes, in MySQL and MariaDBNo, legacy only
After a crashRecovers itself from its redo log on restartTables can be marked as crashed
REPAIR TABLENot supportedSupported
Transactions and row lockingYesNo

To see which engine each table uses, run:

sql
SELECT table_name, engine
FROM information_schema.tables
WHERE table_schema = 'your_database';

If you still have MyISAM tables that crash repeatedly, convert them to InnoDB once they are repaired: ALTER TABLE your_table ENGINE=InnoDB;. That is the most effective way to prevent repeat corruption.

2. On shared hosting: check and repair in the control panel

On shared hosting you don't have root access to the database server, so the command-line and configuration steps later in this guide don't apply. You can still check, repair and optimise your own tables.

  1. Export a backup
    of the database in phpMyAdmin.
  2. Check the tables.
    In cPanel, open MySQL Databases and use Check Database under Modify Databases. In any panel, open phpMyAdmin, click the database, tick the tables and choose Check table from the With selected menu.
  3. Repair a damaged table.
    In cPanel, use Repair Database on the same page. In phpMyAdmin, tick the table named in the error and choose Repair table.
  4. Optimise if needed.
    In phpMyAdmin, tick the tables and choose Optimize table. This is only worth doing after you have deleted a large amount of data.
  5. Test your site
    and check that recent content is still there.

If a repair fails, or the table crashes again, open a support ticket with the database and table names. For connection errors, "Too many connections" and import problems, see Database troubleshooting.

3. Check tables on your own server

With shell access to your own VPS or server, you can check tables in SQL:

sql
CHECK TABLE your_database.your_table;

Or check whole databases with mysqlcheck. On MariaDB the same tool is also called mariadb-check.

bash
mysqlcheck --check your_database
mysqlcheck --check --all-databases

Keep the password off the command line, where it shows in the process list; use an option file readable only by you:

ini
# ~/.my.cnf  (chmod 600)
[client]
user=maint_user
password=use-a-long-random-password

mysqlcheck --check locks each table while it reads it. Run it outside busy hours on a live site.

4. Repair MyISAM tables

For a MyISAM table marked as crashed:

sql
REPAIR TABLE your_database.your_table;

or for a whole database:

bash
mysqlcheck --repair your_database

Treat REPAIR TABLE ... USE_FRM as a last resort only: it can lose data.

Before a repair, free disk space if the disk is full. A full disk during a write is a common cause of crashed tables, and the repair will fail or the table will crash again.

5. Recover from InnoDB corruption

InnoDB replays its redo log after an ordinary crash and needs no repair. Real corruption shows as the server refusing to start, or crashing when a particular table is read, with InnoDB errors in the error log. Follow this order.

  1. Copy the data directory first.
    Stop the server and copy the whole data directory (often /var/lib/mysql) somewhere safe. Every later step works on the original, so this copy is your safety net.
  2. Start in forced recovery.
    Add innodb_force_recovery = 1 under [mysqld] in the server's configuration file, then start the service. If it won't start, raise the value one step at a time. Values 1 to 3 are relatively safe. Values 4 and above can permanently corrupt data files; use them only to dump data, and only after step 1.
  3. Dump everything you can.
    Run mysqldump --single-transaction --routines --triggers --all-databases > full-dump.sql. If one table fails, dump the others table by table.
  4. Rebuild cleanly.
    Remove the recovery setting, set up a fresh, empty data directory, start the server and import the dump.
  5. Check the result.
    Compare row counts on important tables, test the applications, and keep the copied data directory until you are sure.
Never delete ibdata1 or the redo logs

Old guides suggest deleting ibdata1, ib_logfile* or the undo files to "reset" InnoDB. That destroys the data dictionary and uncommitted changes, and can make every InnoDB table unreadable. Rebuild from a dump instead.

For a table that is readable but damaged, ALTER TABLE your_table ENGINE=InnoDB; rebuilds it from its own rows, which is often enough.

6. Optimise tables and queries

OPTIMIZE TABLE rebuilds a table to reclaim space. On InnoDB it recreates the table and updates index statistics. It is worth running after deleting a large share of a table's rows, not on a schedule. It needs free disk space about the size of the table.

sql
OPTIMIZE TABLE your_database.your_table;
ANALYZE TABLE your_database.your_table;

Bigger gains come from the queries themselves:

  • Find the slow ones. Turn on the slow query log (slow_query_log = 1, long_query_time = 1) and review it.
  • Read the plan. Put EXPLAIN before a slow SELECT. A full table scan on a large table usually means a missing index.
  • Index what you filter and join on. Columns in WHERE, JOIN and ORDER BY clauses are the candidates.
  • Drop unused indexes, because each one slows down every insert and update.

For WordPress sites, most database slowness comes from plugins and the size of the wp_options autoload data. See My website is slow.

7. Server settings that still matter

These settings apply to your own server only. Change one at a time, and measure before and after.

ini
[mysqld]
# 50-70% of RAM on a database-only server; less if the
# same server also runs the web server and PHP
innodb_buffer_pool_size = 1G
# 1 = durable; 2 risks losing ~1 s of writes in a crash
innodb_flush_log_at_trx_commit = 1

max_connections = 150
slow_query_log = 1
long_query_time = 1

Leave most other settings at their defaults; modern versions choose sensible values. Some tuning advice is out of date:

  • Query cache: removed in MySQL 8 and disabled by default in MariaDB. Don't enable it.
  • innodb_thread_concurrency and huge sort or join buffers: leave them alone unless you have measured a problem. Large per-connection buffers waste memory.
  • expire_logs_days: replaced in MySQL 8 by binlog_expire_logs_seconds.
  • mysqlpump: deprecated and removed in MySQL 8.4. Use mysqldump, or a physical backup tool for large databases.

Check your version with SELECT VERSION(); before copying any setting, and restart the service (systemctl restart mysql or systemctl restart mariadb, depending on your system) to apply changes.

8. Automate backups, not repairs

A nightly job that "checks and repairs everything" hides problems and can lock tables at the wrong moment. Schedule a nightly mysqldump --single-transaction to a compressed file instead, keep several days of copies with at least one off the server, and test a restore now and then. Check tables only when you see an error.

9. Running this on Domain India

  • Shared hosting (cPanel, DirectAdmin, Webuzo): use phpMyAdmin and your panel's database tools as in section 2. You cannot change server settings. Port 3306 is closed to outside connections, so for a desktop client use an SSH tunnel. Jailed SSH access is available on every shared hosting plan (cPanel, DirectAdmin, Webuzo). It is off by default; ask support to enable it for your account. Logins use an SSH key. On cPanel, phpMyAdmin imports files up to 50 MB. Weekly JetBackup 5 backups on cPanel and DirectAdmin include your databases and can be restored from the panel.
  • VPS: a Domain India VPS is self-managed with root access, so sections 3 to 8 apply in full. You are responsible for the database server's configuration and backups.
VPS Starter
₹552.65/mo + GST
  • 1 vCPU
  • 2 GB DDR4 RAM
  • 64 GB NVMe SSD Storage
  • 2 TB Monthly Bandwidth
See plan details
How do I repair a crashed MySQL table?

Back up the database first. On shared hosting, use Repair Database in cPanel's MySQL Databases page or Repair table in phpMyAdmin. On your own server, run REPAIR TABLE or mysqlcheck --repair. This works for MyISAM tables; InnoDB tables use crash recovery instead.

Does REPAIR TABLE work on InnoDB?

No. InnoDB recovers automatically after most crashes. For real corruption, start the server with innodb_force_recovery, dump the data and rebuild. To rebuild a readable table, run ALTER TABLE with ENGINE=InnoDB.

Is it safe to delete ibdata1 to fix InnoDB?

No. Deleting ibdata1 or the redo log files can make every InnoDB table unreadable. Copy the data directory, use forced recovery to dump the data, and rebuild from the dump.

Can I change MySQL settings on shared hosting?

No. Server settings such as the buffer pool size are shared by every account on the server. You can check, repair and optimise your own tables in phpMyAdmin. For full control, use a VPS.

How do I connect to my database from my computer on Domain India shared hosting?

Port 3306 is closed to outside connections. Use phpMyAdmin in your control panel, or an SSH tunnel once jailed SSH has been enabled on your account by support.

Ready to go further? Read Database troubleshooting for common errors, How to connect to the MySQL database for connection details, or compare VPS plans if you need your own database server.

Need help with a damaged database?

Send the domain, the database and table names and the exact error message. Never include your database password.

Open a support ticket

Was this article helpful?

Your answer helps us decide what to improve next.

Still need help? Open a support ticket and our team will reply.

Prefer an app? Add this site to your home screen.Get the app