Checking mysql replication
Question: What happens if you have two mysql database with replication, they stop replicating and you do not notice?
Answer: you get into trouble....
Here is a small script to help you stay informed...
Answer: you get into trouble....
Here is a small script to help you stay informed...
#!/usr/bin/php
/* Connessione e selezione del database */
$connessione = mysql_connect("localhost", "root", "secretpw")
or die("Connessione non riuscita");
print "Connesso con successo\n";
/* Esecuzione di una query SQL */
$query = "SHOW SLAVE STATUS";
$risultato = mysql_query($query) or die("Query fallita");
$slaveok=0;
while ($row = mysql_fetch_array($risultato, MYSQL_ASSOC)) {
print "Slave is running: ".$row["Slave_Running"] . "\n";
print "Last error : ".$row["Last_error"] . "\n";
if ($row["Slave_Running"]=="Yes" && $row["Last_error"]=="") {
$slaveok=1;
}
}
/* Liberazione delle risorse del risultato */
mysql_free_result($risultato);
/* Chiusura della connessione */
mysql_close($connessione);
if ( ! $slaveok ) {
system("echo \"Check MYSQL replication on web1!\" | mail -s \"MYSQL replication on web1\" admin ");
?>