The corrupt table entry is logged in the error file something like this…
/usr/local/mysql/bin/mysqld: Incorrect
key file for table
‘./accounts/headers.MYI’; try to
repair it
I want to write a query that will repair this table.
REPAIR TABLE accounts.headers;
What I need to do is search for the first instance of “./” and select the first word i.e. “accounts” and choose the next word “headers”.
Now use these two variables to write a statement like shown above.
Should I write a Shell script for this purpose?
You can use
grepandsedto do this:Note that I’ve put all those
-esections on different lines for readability. They should be all on one line to test.If your version of
sedsupports case-insensitive searches (like the GNU one does), you can replace that last substitution with's/\.myi.*/;/Ig'.To catch lines with different foramts is a bit trickier and will require all the formats to be known to avoid false positives. The following command will catch the alternate format as supplied in your comment: