Combat: Custom Script off Mysql-mysql 5.6.19

Source: Internet
Author: User

Customize a MySQL shutdown script based on the working environment


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

#set MySQL init variables
Mysql_user=system #mysql的用户名
mysql_pass= ' Password ' #mysql的登录用户密码

#check input parameter or no
If [$#-ne 1]; Then #判断输入的参数个数
echo "MySQL port is 3306"
mysql_port=3306
Else
Mysql_port=$1 #$1 is the 1th positional parameter passed in
echo "MySQL Port is $"

Fi


---2. Turn off MySQL


#!/bin/sh
#[email protected]

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

MY_CNF=/USR/LOCAL/MYSQL/MY.CNF #mysql的配置文件

Mysqld_admin=/usr/local/mysql/bin/mysqladmin

Mysql_socket=/usr/local/mysql/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 "MySQL Installation when startup file is not installed to $mysqld_admin or no execute permission"
Exit 0
elif [$PORTNUM = 0]; then
echo "MySQL is off, no need to close!"
Exit 0
Else
echo "Turn off MySQL service"
${mysql_cmd} shutdown
While [$INIT _num-le 5]
Do
portnum= ' Netstat-lnt|grep ${mysql_port}|wc-l '
echo "MySQL off in .... Please wait a moment ... "
Sleep 5
if [$PORTNUM = 0];
Then
echo "MySQL * * * * * * success"
Exit 0
Fi

init_num=$ (($INIT _num + 1))
Done
Echo-e "MySQL shutdown failed, please 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


This article is from "Record bit!" "Blog, be sure to keep this provenance http://ocpyang.blog.51cto.com/3401739/1426813

Related Article

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.