Need to start multiple MySQL instances on the server today
The new MySQL instance can not be managed with mysqld_multi, so it has customized a mysql_3307 service, with service management
You can look at the service code, which are simple shell scripts.
The principle of service is to go to/etc/init.d to find the corresponding service script, and then invoke the script, the service's second parameter is passed to the invocation of the services as the first parameter
Therefore, you can write a script under/ETC/INIT.D, define the corresponding start,stop,status in the script, or you can add some other actions on your own, and you can add an execution permission.
Here is my mysql_3307 definition script:
Start () {n=$ (netstat -ntlp |grep 3307|grep -v "grep 3307" |wc -l) if [ $n -ne 0 ];then echo "server is already running!" exit 0fimysqld_multi --defaults-extra-file=/etc/my_3307.cnf --user=root start 3307if [ $? -eq 0 ];then echo "Service mysql_3307 start successful "else echo " Service mysql_3307 start fail "Fi}stop () {n=$ (netstat -ntlp |grep 3307|grep -v "grep 3307" |wc -l) if [ $n -eq 0 ];then echo "server is not running!" fimysqld_multi --defaults-extra-file=/etc/my_3307.cnf --user=root stop 3307if [ $? -eq 0 ];then echo "service mysql_3307 stop successful " Else echo "Service mysql_3307 stop fail" Fi}sTatus () {ps -ef |grep 3307|grep -v "grep 3307"}case $1 instart) start;; Stop) stop;; Status) status;; *) echo ' service accept arguments start|stop|status ' Esac
This article is from the "Epimetheus" blog, make sure to keep this source http://epime.blog.51cto.com/10727900/1696546
Linux Service Management Custom scripts