3

I need to build a report from the output of MySQL database check and auto-repair.
But dont want the full report each time : only in case of repair was needed

A scheduled (cron) a task runs mysqlcheck
I want to get informed by email of eventual repair needed, repair success, repair fails...
But dont want the full report each time : only repairs

I run the mysqlcheck like this:

mysqlcheck --user=myuser --password=mypwd -c --auto-repair dbname > ouput.log

Found on a blog that the mysqlcheck output may looks like this in case of repair

Repairing tables
dbname.table1
warning  : Number of rows changed from 3 to 1
status   : OK
dbname.table2
warning  : Number of rows changed from 5454 to 5455
status   : OK
dbname.table3
warning  : Number of rows changed from 471859 to 471860
status   : OK

Since i cant find any official documentation about how looks the exact output, I need help to build a report text file made by processing the output of mysqlcheck.
Perhaps some regex magician can make a report giving repaired tables names, faillure notice and so.

This refers to the mysql server available on official Ubuntu repositories
mysql-server 5.7.25-0ubuntu0.18.04.2

cmak.fr
  • 8,696

3 Answers3

2

This simple script is getting the mysqlcheck result and checking the output for "Repairing Tables". As this string only comes when the table is damaged.

If exist then it sends an email to the desired address.

#!/bin/bash

result=`mysqlcheck --user=myuser --password=mypass --auto-repair dbname;`

if [[ $result == *"Repairing tables"* ]]; then

  echo $result | mailx -s 'email subject'  username@example.com

fi
Mohit Malviya
  • 586
  • 2
  • 9
  • Hi @Mohit Malviya. Did you find some information reference about the output of mysqlcheck ? – cmak.fr Apr 21 '19 at 12:59
  • 2
    Yes, I successfully simulate the environment. I manually damage a table and then try to repair it using mysqlcheck. You also can have a look at https://pastebin.com/2Lsbn5Mz – Mohit Malviya Apr 22 '19 at 03:53
  • How did you damage a table ? - 2. regarding to your paste, did the repair be successfull ? 3. Many thanks
  • – cmak.fr Apr 22 '19 at 04:25
  • 1
  • I manually edit the file "ad_overlay_codes.frm" Which is present in "/var/lib/mysql". 2. While i edit the file manualluy and delete some data of it, The repair is unsuccessful. 3. Welcome.
  • – Mohit Malviya Apr 22 '19 at 05:55