Practice: Customize scripts to start mysql-mysql5.6.19_MySQL

Source: Internet
Author: User
Practice: Customize scripts to start the mysql-mysql5.6.19 according to the work environment, customize a mysql startup script

--- 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

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.