Skip to content

Instantly share code, notes, and snippets.

@rothkj1022
Created April 10, 2019 17:05
Show Gist options
  • Save rothkj1022/233bd389c6cff8a327dd21e9b142be0a to your computer and use it in GitHub Desktop.
Save rothkj1022/233bd389c6cff8a327dd21e9b142be0a 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