Combat: Custom Script Launcher Mysql-mysql 5.6.19

Source: Internet
Author: User

Customize a MySQL startup script based on your work 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. Start MySQL

#!/bin/sh
#[email protected]

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

Mysqld_safe=/usr/local/mysql/bin/mysqld_safe

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

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 _safe]; Then
echo "MySQL Installation when startup file is not installed to $mysqld_safe or no execute permission"
Exit 1 #0是执行成功, 1 is execution unsuccessful
Else
if [$PORTNUM = 1]; Then
echo "A mysqld process already exists,please stop MySQL at first!"
Exit 0
Else
echo "Start native MYSQL Port: $MYSQL _port Service"
$MYSQLD _safe--defaults-file= $MY _cnf >/dev/null &
While [$INIT _num-le 5]
Do
portnum= ' Netstat-lnt|grep ${mysql_port}|wc-l '
echo "MySQL startup .... Please wait a moment ... "
Sleep 5
if [$PORTNUM = 1];
Then
echo "MySQL Startup success * * * * * * * * *"
Exit 0
Fi

init_num=$ (($INIT _num + 1))
Done
Fi
Echo-e "MySQL boot 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

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.