This is a small bash script that checks all mysql databases for errors and mails a log file to a specified email address.
-
Use the following environment variables to override default configuration values:
OPTIONS_FILE
- The path to a MySQL options file containing auth credentials (default :~/.my.cnf
; see Using Options Files)DBHOST
- The MySQL server hostname (default:localhost
)LOGFILE
- The path where you'd like to save theautomysqlcheck
log file (default: /var/log/automysqlcheck.log`)MAILTO
- The email address to send the summary to upon completion (default:root@localhost
)MAILFROM
- The email address to send the summary fromDBNAMES
- A space delimited list of database names to check (orall
; default:all
)DBEXCLUDE
- A space delimited list of database names to skip (default: none)
-
Create a MySQL options file at the path specified above which contains auth credentials, for example:
[mysql] user=root password=SECRET_PASSWORD
-
Add
automysqlcheck
to your crontab or install the macOS launchd .plist file, specifying environment variables to override any necessary configuration values.
This was originally published on http://dev.mysql.com/doc/refman/5.0/en/check-table.html#c5003 by Stuart Bray and modified by the community.
Copyright (c) 2004 Stuart Bray
Copyright (c) 2005 eyechart
Copyright (c) 2006 Mickael Sundberg
Copyright (c) 2006 Jake Carr
Copyright (c) 2010 Fabrizio La Rosa
Copyright (c) 2011 Morgan Aldridge