MySQL 1240: Partition is corrupted.

  1. Immediate Backup: Before attempting any fix, take an immediate backup of the database, if possible, to prevent data loss. Use the command:


mysqldump -u yourusername -p yourdatabasename > backupname.sql

  1. Check and Repair the Table: Use the `CHECK TABLE` command to verify the integrity of the table, followed by the `REPAIR TABLE` command if issues are found. Replace `yourtablename` with the name of your corrupted table.


CHECK TABLE yourtablename;
REPAIR TABLE your
tablename;

  1. MySQL Error Log: Review the MySQL error log for any messages related to the corruption. The location of the log can be found by executing:


SHOW VARIABLES LIKE 'log_error';
Then, view the log file for specific error entries related to the corruption.

  1. File System Check: Consider running a file system check if the table's corruption might be due to underlying disk issues. Use the command (for Linux systems):


fsck /dev/sdX
Note: Replace `/dev/sdX` with your actual device. This action requires system administrator privileges and should be done during a maintenance window as it requires unmounting the filesystem.

  1. InnoDB Recovery Mode: If the corrupted table is an InnoDB table, adjusting the InnoDB recovery mode might help in starting the MySQL server if it's failing to start. Edit the `my.cnf` or `my.ini` file, adding the following under the `[mysqld]` section:


innodbforcerecovery = 1
Start with `1` and increment up to `6`, but be cautious: higher levels prevent changes to the database. Only use this to dump tables for backup. After adjusting, try restarting the MySQL service and dump your data.

  1. Restore from Backup: If you have a recent backup that predates the corruption, consider restoring the table or database from this backup.



  1. Use of External Tools: For severe corruption, external tools like `mysqlcheck` or third-party recovery tools might be necessary. To run a check on all tables and repair them with `mysqlcheck`, use:


mysqlcheck -u your_username -p --auto-repair --check --all-databases

Master

MySQL

in Minutes — Grab the Ultimate Cheatsheet

(Perfect for DevOps & SREs)

Most-used commands
Real-world configs/examples
Handy troubleshooting shortcuts
Your email is safe with us. No spam, ever.

Thankyou for your submission

We have sent the cheatsheet on your email!
Oops! Something went wrong while submitting the form.

MySQL

Cheatsheet

(Perfect for DevOps & SREs)

Most-used commands
Your email is safe with us. No spam, ever.

Thankyou for your submission

We have sent the cheatsheet on your email!
Oops! Something went wrong while submitting the form.

MORE ISSUES

Made with ❤️ in Bangalore & San Francisco 🏢

Doctor Droid