In Linux, check whether MySQL Slave is normal.

Source: Internet
Author: User
I wrote a script to check whether MySQLREPLICATION's SLAVE is normal in Linux, which is relatively simple. If you want to run it with CRONTAB, remove the Read part. 1. Script

I wrote a script to check whether the SLAVE of MySQL REPLICATION is normal in Linux, which is relatively simple. If you want to run it with CRONTAB, remove the Read part. 1. Script

I wrote a script to check whether the SLAVE of MySQL REPLICATION is normal in Linux, which is relatively simple.
If you want to run it with CRONTAB, remove the Read part.
1. Run the MYSQL Command show status to View Script 1.
[Root @ localhost ~] # Cat slave_is_running

#! /Bin/sh

#

# Created by david yeung

#

# To determine whether slave is running or not.

Echo "Enter your Username"
Read USERNAME
Echo "Enter your password"
Stty-echo
Read PASSWD
Stty echo
Cd/usr/local/mysql/bin

RESULT = './mysql-u $ USERNAME-p $ PASSWD-e' show status like "Slave_running" '-ss | awk' {print $2 }''
If ["$ RESULT" = 'on']
Then
Echo "Slave is running! ">/Var/log/mysql_slave.log
Else
Echo "Slave is not running! ">/Var/log/mysql_slave.log
Fi

2. Script 2 is implemented through the MYSQL Command show slave status \ G

#! /Bin/sh

#

# Created by david yeung

#

# To determine whether slave is running or not.

Echo "Enter your Username"
Read USERNAME
Echo "Enter your password"
Stty-echo
Read PASSWD
Stty echo
Cd/usr/local/mysql/bin

RESULT = '. /mysql-u $ USERNAME-p $ PASSWD-e 'show slave status \ G'-ss | awk' {print $2} '| head-n 13 | tail-n2'
If ["$ RESULT" = 'yes yes']
Then
Echo "Slave is running! ">/Var/log/mysql_slave.log
Else
Echo "Slave is not running! ">/Var/log/mysql_slave.log
Fi

3. Test

[Root @ localhost ~] #./Slave_is_running
Enter your Username
Root
Enter your password
[Root @ localhost ~] # Cat/var/log/mysql_slave.log
Slave is running!

I stopped SLAVE.
[Root @ localhost ~] # Cat/var/log/mysql_slave.log
Slave is not running!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.