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