This script connects to a MySQL Server and checks the consistency of a given database.

How does it work?

check_mysql_db_integrity uses the mysqlcheck binary shipped with MySQL. (also refer to MySQL Manual - deutsch) That's why you need to install MySQL on the server you want the script to run on.

The output of mysqlcheck is dumped into a LOG file, so we can later grep for errors. If no errors were found, LOG file will be deleted. Otherwise LOG File will be kept and a e-mail is sent to the administrator

Exit Codes where modified to fit in Nagios Plugin requirements.

How to use?


  1. Install MySQL

  2. copy script to the server and make it executable (chmod +x check_mysql_db_integrity)

  3. set your e-mail address in the script (line 22)

  4. get required data: database host, database name, username and password

Within Nagios

  1. create command defintion

which may look like this:

'check_mysql' command definition

define command{

    command_name check_mysql     command_line $USER1$/check_mysql $HOSTADDRESS$ $ARG1$ $ARG2$ $ARG3$ $ARG4$ }

ARG1 -> database

  • ARG2 -> user
  • ARG3 -> password
  • ARG4 -> [-r] (repair mode for event_handler)
  1. create service definition

which may look like this

  • check that iss running and consistent

  • check_mysql parameter: check_mysql!database!user!password

    define service { host_name               service_description     check_command           check_mysql!!! use                     generic-service notification_interval   0 ; set > 0 if you want to be renotified }


  • Just call the script with necessary parameters (call without parameters to get usage information)

-> use the following parameters (in exactly this order): $host $database $user $password

  • The [-r] parameter is optional. To use the repair mode, you need to provide credentials with write permissions on the database. Then mysqlcheck will try to repair corrupted databases.

example:./check_mysql_db_integrity my_database my_user secret