Skip to content

Instantly share code, notes, and snippets.

@heartshare
Forked from rothkj1022/mysql_check.sh
Created August 28, 2024 02:58
Show Gist options
  • Save heartshare/c5c426558b58d0bd50472192184ebd2a to your computer and use it in GitHub Desktop.
Save heartshare/c5c426558b58d0bd50472192184ebd2a to your computer and use it in GitHub Desktop.
Script for checking and repairing MySQL databases & tables, including corrupted InnoDB tables
#!/bin/bash
# set mysql into innodb recovery mode on startup
mode=1; sed -i "/^\[mysqld\]/{N;s/$/\ninnodb_force_recovery=$mode/}" /etc/my.cnf
# restart mysql
systemctl restart mysqld
# remove recovery mode setting
sed -i '/innodb_force_recovery/d' /etc/my.cnf
# restart mysql into normal mode
systemctl restart mysqld
# check and auto repair databases
mysqlcheck --all-databases --auto-repair
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment