Smart Systems for Home

Plain how-to guides for smart home, security and home Wi-Fi

Fix MySQL InnoDB Errors That Crash the Server

· 6 min read · Home Tech

In this article
  1. What You'll Need
  2. Step-by-Step
  3. Common Mistakes
  4. Tips
  5. Troubleshooting
  6. Frequently Asked Questions

MySQL InnoDB errors can bring your database server down, causing downtime and potential data loss. This guide walks you through diagnosing and fixing the most common InnoDB issues—corrupted tables, full disks, misconfigured buffers, and crash recovery failures—so you can get your server stable again. You’ll need root or sudo access to the MySQL server and the ability to restart the service.

What You'll Need

  • SSH or console access to the MySQL server (root or a user with sudo privileges).
  • MySQL client (mysql command) installed on the server or a machine that can connect.
  • Basic familiarity with the command line and MySQL configuration files (my.cnf or my.ini).
  • A recent backup of your databases, if possible, before making changes.

Step-by-Step

  1. Identify the exact error. Check the MySQL error log (usually at /var/log/mysql/error.log or /var/log/mysqld.log). Look for lines containing "InnoDB" and note the error code (e.g., 1114, 1213, 126, 129, 1419) and the table or file mentioned. Common messages include "Table is full", "InnoDB: Corruption", "InnoDB: Unable to lock ./ibdata1", or "InnoDB: Operating system error number 28" (disk full).
  2. Check disk space. Run df -h on the server. If the partition holding MySQL data (usually /var/lib/mysql) is 100% full, InnoDB can crash. Free up space by removing old backups, logs, or temporary files. If you cannot free space immediately, you may need to move the data directory to a larger volume (see Troubleshooting).
  3. Verify InnoDB file permissions. Ensure the MySQL user (often mysql) owns the data directory and files. Run chown -R mysql:mysql /var/lib/mysql (adjust path if needed). Incorrect ownership can cause InnoDB to fail on startup.
  4. Attempt a clean shutdown and restart. If the server is still running, try a graceful shutdown: mysqladmin shutdown. Then start it again with systemctl start mysql (or service mysql start). Sometimes InnoDB can recover from a crash during startup if the log files are intact.
  5. Run InnoDB recovery (if startup fails). If the server won't start, set innodb_force_recovery in the MySQL config file to a low value (1, then 2, etc.) to skip certain checks and allow startup. Start with 1, then try to start the server. If it fails, increase to 2, then 3, and so on up to 6. Do not leave this setting on permanently; it disables some safety features.
  6. Dump and restore the affected database. Once the server starts (even in recovery mode), immediately dump the data using mysqldump --all-databases > backup.sql. This is your safety net. If you can, dump only the affected tables: mysqldump dbname tablename > table.sql.
  7. Repair corrupted tables. With the server running, use mysqlcheck to check and repair InnoDB tables: mysqlcheck -u root -p --auto-repair --check dbname or for all databases: mysqlcheck -u root -p --auto-repair --all-databases. Note that InnoDB does not support the REPAIR TABLE command; you must use mysqlcheck or dump and restore.
  8. Rebuild the table if repair fails. If a specific table is corrupted and cannot be repaired, drop it and recreate it from a backup. If you have no backup, try to export the data with mysqldump using the --force flag to skip errors, then import into a new table.
  9. Check and adjust InnoDB settings. After recovery, review your config for common pitfalls: innodb_buffer_pool_size should be about 70-80% of available RAM (but not causing swapping). innodb_log_file_size should be large enough (e.g., 256M or 512M) to avoid frequent checkpoints. If you changed these, restart MySQL normally.
  10. Remove the force_recovery setting. Once the server is stable, remove innodb_force_recovery from the config and restart MySQL to run in normal mode. Verify all tables are accessible with mysqlcheck again.

Common Mistakes

  • Leaving innodb_force_recovery enabled permanently. This can cause silent data corruption because InnoDB skips certain operations.
  • Ignoring disk space warnings. InnoDB crashes when the disk is full, and if you don't free space, the crash will recur.
  • Running REPAIR TABLE on InnoDB tables—it doesn't work and may give a false sense of action.
  • Increasing innodb_buffer_pool_size without enough RAM, causing the system to swap and further slow down or crash.
  • Not backing up before making config changes. Always have a recent dump before touching InnoDB settings.

Tips

  • Enable the error log and set log_error to a file outside the data directory to preserve logs even if the data directory is corrupted.
  • Set up regular automated backups with mysqldump or a tool like Percona XtraBackup to minimize data loss.
  • Monitor disk space and InnoDB status with tools like mysqladmin status and SHOW ENGINE INNODB STATUS\G to catch issues early.
  • If you suspect hardware issues (bad disk, RAM), run memory tests (memtest) and check disk health with smartctl.
  • Consider using a separate disk or partition for the MySQL data directory to avoid filling up the root filesystem.

Troubleshooting

If the server still crashes after following the steps:

  • Startup fails even with force_recovery=6. This indicates severe corruption. Restore from your last backup. If you have no backup, you may need to hire a data recovery specialist.
  • Error "Unable to lock ./ibdata1" means another MySQL process is running. Stop it with systemctl stop mysql or kill the process, then try again.
  • Error "Operating system error number 28" is disk full. Free space or move the data directory to a larger volume. To move, stop MySQL, copy the data directory to the new location, update datadir in the config, and restart.
  • InnoDB hangs during recovery. Wait a few minutes—recovery can take time for large databases. If it hangs indefinitely, check if the disk is slow or if there's a deadlock; you may need to increase innodb_force_recovery further.
  • After recovery, some tables show "Table doesn't exist". This can happen if the .ibd file is missing. Check the data directory for the table's .ibd file. If missing, you may need to restore that table from backup.
  • Crash recurs after a while. Check for underlying hardware issues (bad RAM, failing disk) and review your InnoDB settings. Also check for large temporary tables that fill the disk.

Frequently Asked Questions

Can I use REPAIR TABLE on InnoDB tables?

No. InnoDB does not support REPAIR TABLE. Use mysqlcheck --repair or dump and restore the table.

What does innodb_force_recovery do?

It tells InnoDB to skip certain checks and operations during startup to allow the server to start even with corruption. Values from 1 to 6 increase the level of skipping, but also increase the risk of data loss.

How do I know if my disk is full?

Run df -h and look at the usage percentage of the partition containing the MySQL data directory. If it's 100%, that's the cause.

Will I lose data if I set innodb_force_recovery?

Potentially, yes. Higher levels skip more operations, which can lead to uncommitted transactions being lost or corrupted pages being skipped. Always back up as soon as possible after starting in recovery mode.

How can I prevent InnoDB crashes in the future?

Keep your disk from filling up, monitor server health, use proper buffer pool sizing, and perform regular backups. Also consider using a RAID array or SSD for better reliability.

What is the InnoDB buffer pool and why does it matter?

It's the memory area where InnoDB caches data and indexes. If it's too small, performance suffers; if too large, the system may swap. Set it to about 70-80% of available RAM.