Practice: Close mysql-mysql 5.6.19 with a custom script

Source: Internet
Author: User

Customize a mysql close script according to the working environment

 

--- 1. Save As/usr/local/mysql/scripts/mysql_env.ini

# Set mysql init variables
MYSQL_USER = system # mysql Username
MYSQL_PASS = 'Password' # mysql logon User password

# Check input parameter or no
If [$ #-ne 1]; then # determines the number of input parameters
Echo "mysql port is 3306"
MYSQL_PORT = 3306
Else
MYSQL_PORT = $1 #$1 is the input 1st location parameter.
Echo "mysql port is $1"

Fi

 

--- 2. Disable mysql

 

#! /Bin/sh
# Ocpyang@126.com

Source/usr/local/mysql/scripts/mysql_env.ini

MY_CNF =/usr/local/mysql/my. cnf # mysql configuration file

MYSQLD_ADMIN =/usr/local/mysql/bin/mysqladmin

MYSQL_SOCKET =/usr/local/mysql. sock

MYSQL_CMD = "$ {MYSQLD_ADMIN}-u $ {MYSQL_USER}-p $ {MYSQL_PASS}-S $ {MYSQL_SOCKET }"

ERRORLOG = 'grep-I "^ log-error" $ MY_CNF | cut-d =-f 2'

INIT_NUM = 1

PORTNUM = 'netstat-lnt | grep $ {MYSQL_PORT} | wc-l'

If [! -X $ MYSQLD_ADMIN]; then
Echo "the mysql Startup file is not installed in $ MYSQLD_ADMIN or has no execution permission"
Exit 0
Elif [$ PORTNUM = 0]; then
Echo "mysql is in the closed State and does not need to be closed! "
Exit 0
Else
Echo "Disable mysql service"
$ {MYSQL_CMD} shutdown
While [$ INIT_NUM-le 5]
Do
PORTNUM = 'netstat-lnt | grep $ {MYSQL_PORT} | wc-l'
Echo "mysql is shutting down... please wait ..."
Sleep 5
If [$ PORTNUM = 0];
Then
Echo "mysql ***** closed successfully ****"
Exit 0
Fi
 
INIT_NUM = $ ($ INIT_NUM + 1 ))
Done
Echo-e "mysql disabling failed. Check the error log 'echo 'cat' $ {ERRORLOG }'"
Echo "************************************** ***"
Exit 0
Fi

 

 

 

 

--- 3. Add environment variables.

 

Echo "export PATH =/usr/local/mysql/scripts: \ $ PATH" >> ~ /. Bash_profile


Source ~ /. Bash_profile

 

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.