MySQL master-slave configuration script

Source: Internet
Author: User

passwd=123456
User=root
rep_host=10.10.10.70
rep_port=3306
Rep_user=slave
[Email protected]
rep_file=mysql-bin.000021
rep_pos=863718

if [!-f/var/lock/mysql-zc.lock];then
Mysql-u$user-p$passwd-e "Change Master to master_host= ' $REP _host ', master_port= $REP _port, master_user= ' $REP _user ', master_password= ' $REP _passwd ', master_log_file= ' $REP _file ', master_log_pos= $REP _pos; "
Touch/var/lock/mysql-zc.lock
Fi
Start () {
if [!-f/var/lock/mysql-start.lock];then
Mysql-u$user-p$passwd-e "Start slave;"
Sleep 1
Mysql-u$user-p$passwd-e "show slave status\g;" | Grep-e "Slave_sql_running| Slave_io_running "
Touch/var/lock/mysql-start.lock
[-f/var/lock/mysql-stop.lock]&&rm-rf/var/lock/mysql-stop.lock
Else
echo "Slave is start!!!"
Fi

}
Stop () {
if [!-f/var/lock/mysql-stop.lock];then
Mysql-u$user-p$passwd-e "Stop Slave;"
Mysql-u$user-p$passwd-e "show slave status\g;" | Grep-e "Slave_sql_running| Slave_io_running "
Touch/var/lock/mysql-stop.lock
[-f/var/lock/mysql-start.lock]&&rm-rf/var/lock/mysql-start.lock
Else
echo "Slave is STOP!!!"
Fi
}

Case "$" in
Start
Start
;;
Stop
Stop
;;
Status
Mysql-u$user-p$passwd-e "show slave status\g;" | Grep-e "Slave_sql_running| Slave_io_running "
;;
*)
echo "usage:start| Stop|status "
;;
Esac

MySQL master-slave configuration script

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.