Practice: Start mysql-mysql 5.6.19 with a custom script

Source: Internet
Author: User

Customize a mysql STARTUP 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. Start mysql

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

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

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 "the mysql Startup file is not installed in $ MYSQLD_SAFE or has no execution permission"
Exit 1 #0 indicates that the execution is successful, and 1 indicates that the execution is unsuccessful.
Else
If [$ PORTNUM = 1]; then
Echo "A mysqld process already exists, please stop mysql at first! "
Exit 0
Else
Echo "Start the mysql port of the Local Machine: $ 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 is starting... please wait ..."
Sleep 5
If [$ PORTNUM = 1];
Then
Echo "mysql ***** started successfully ****"
Exit 0
Fi
 
INIT_NUM = $ ($ INIT_NUM + 1 ))
Done
Fi
Echo-e "mysql startup 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

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.