I recently had to restore a corrupted table that had resulted from a full disk. I had been using automysqlbackup as my backup script. Each database had a corresponding backup file. It would have been easy to use a text editor to edit out the tables that you didn't want to restore but this database had grown to 1G. STEP 1: Restore table structure If the table structure is corrupted, you need to retrieve the CREATE TABLE statements from the backup. To do this you can use grep: zcat backup.sql.gz | grep -A 20 'CREATE TABLE `tablename1`' > tablestructure.sql This command will create tablestructure.sql containing the CREATE TABLE statement and 20 lines after that. You may have to change the parameter from 20 to whatever to get the entire statement. Once tablestructure.sql had been edited to only contain the proper CREATE TABLE statement, you may now restore the table structure. mysql -u user -p dbname STEP 2: Extract and restore the table data This command will create a sql ...
A blog for collecting tips and tricks on useful tools for your business or personal use. Covers websites, apps and gadgets.