Home > Database > Mysql Tutorial > Onsql和MySQL的启停脚本_MySQL

Onsql和MySQL的启停脚本_MySQL

WBOY
Release: 2016-05-30 17:11:23
Original
1132 people have browsed it

启停onesql,总共四个参数{start|stop|restart|status},只要稍微改一下头部的三个文件路径,即可完成mysql单实例的启停。

 

[#9(zhouxx_vm(node3:192.168.56.103))#root@node3~]#service onesql5.6.26 
Usage:sh /etc/init.d/onesql5.6.26  {start|stop|restart|status}
Copy after login

详细执行效果如下:

[#2(zhouxx_vm(node3:192.168.56.103))#root@node3~]#service onesql5.6.26 status
There is no mysqld process  ! 
[#3(zhouxx_vm(node3:192.168.56.103))#root@node3~]#service onesql5.6.26 stop
The mysqld process is already stopped ! 
[#4(zhouxx_vm(node3:192.168.56.103))#root@node3~]#service onesql5.6.26 start
Starting MySQL.
150830 13:15:06 mysqld_safe Logging to '/data/mysql/mysql_3307/logs/error3307.log'.
150830 13:15:06 mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql_3307/data
Starting MySQL.. SUCCESS! 
[#5(zhouxx_vm(node3:192.168.56.103))#root@node3~]#
[#5(zhouxx_vm(node3:192.168.56.103))#root@node3~]#service onesql5.6.26 status


root      2319     1  2 13:15 pts/0    00:00:00 /bin/sh /usr/local/onesql5.6/bin/mysqld_safe --defaults-file=/data/mysql/mysql_3307/my_3307.cnf --user=mysql --datadir=/data/mysql/mysql_3307/data --basedir=/usr/local/onesql5.6
mysql     3163  2319 44 13:15 pts/0    00:00:02 /usr/local/onesql5.6/bin/mysqld --defaults-file=/data/mysql/mysql_3307/my_3307.cnf --basedir=/usr/local/onesql5.6 --datadir=/data/mysql/mysql_3307/data --plugin-dir=/usr/local/onesql5.6/lib/plugin --user=mysql --log-error=/data/mysql/mysql_3307/logs/error3307.log --open-files-limit=58000 --pid-file=/data/mysql/mysql_3307/logs/mysql_3307.pid --socket=/tmp/mysql_3307.sock --port=3307
MySQL(pid=3163) Status 
 
--------------
/usr/local/onesql5.6/bin/mysql  Ver 14.14 Distrib 5.6.25, for Linux (x86_64) using  EditLine wrapper

Connection id:          4
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.6.26-log (OneSQL) Source distribution
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /tmp/mysql_3307.sock
Uptime:                 5 sec

Threads: 4  Questions: 5  Slow queries: 0  Opens: 18  Flush tables: 1  Open tables: 11  Queries per second avg: 1.000
--------------



[#6(zhouxx_vm(node3:192.168.56.103))#root@node3~]#
[#6(zhouxx_vm(node3:192.168.56.103))#root@node3~]#
[#6(zhouxx_vm(node3:192.168.56.103))#root@node3~]#service onesql5.6.26 stop
150830 13:15:19 mysqld_safe mysqld from pid file /data/mysql/mysql_3307/logs/mysql_3307.pid ended
Stopping MySQL SUCCESS! 
[#7(zhouxx_vm(node3:192.168.56.103))#root@node3~]#service onesql5.6.26 restart
The mysqld process is already stopped ! 
150830 13:15:32 mysqld_safe Logging to '/data/mysql/mysql_3307/logs/error3307.log'.
150830 13:15:32 mysqld_safe Starting mysqld daemon with databases from /data/mysql/mysql_3307/data
Starting MySQL. SUCCESS! 
[#8(zhouxx_vm(node3:192.168.56.103))#root@node3~]#service onesql5.6.26 status


root      3266     1  3 13:15 pts/0    00:00:00 /bin/sh /usr/local/onesql5.6/bin/mysqld_safe --defaults-file=/data/mysql/mysql_3307/my_3307.cnf --user=mysql --datadir=/data/mysql/mysql_3307/data --basedir=/usr/local/onesql5.6
mysql     4107  3266 63 13:15 pts/0    00:00:02 /usr/local/onesql5.6/bin/mysqld --defaults-file=/data/mysql/mysql_3307/my_3307.cnf --basedir=/usr/local/onesql5.6 --datadir=/data/mysql/mysql_3307/data --plugin-dir=/usr/local/onesql5.6/lib/plugin --user=mysql --log-error=/data/mysql/mysql_3307/logs/error3307.log --open-files-limit=58000 --pid-file=/data/mysql/mysql_3307/logs/mysql_3307.pid --socket=/tmp/mysql_3307.sock --port=3307
MySQL(pid=4107) Status 
 
--------------
/usr/local/onesql5.6/bin/mysql  Ver 14.14 Distrib 5.6.25, for Linux (x86_64) using  EditLine wrapper

Connection id:          4
Current database:
Current user:           root@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.6.26-log (OneSQL) Source distribution
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    utf8
Db     characterset:    utf8
Client characterset:    utf8
Conn.  characterset:    utf8
UNIX socket:            /tmp/mysql_3307.sock
Uptime:                 4 sec

Threads: 4  Questions: 5  Slow queries: 0  Opens: 18  Flush tables: 1  Open tables: 11  Queries per second avg: 1.250
--------------



[#9(zhouxx_vm(node3:192.168.56.103))#root@node3~]#
Copy after login


详细脚本

[#10(zhouxx_vm(node3:192.168.56.103))#root@node3~]#cat /etc/init.d/onesql5.6.26 
#!/bin/sh
##source /etc/profile

#MYSQL_HOME=/usr/local/mysql5.6.26
MYSQL_HOME=/usr/local/onesql5.6
datadir=/data/mysql/mysql_3307/data
mysql_cnf="/data/mysql/mysql_3307/my_3307.cnf"
mysql_sock="/tmp/mysql_3307.sock"

function start(){
mysqld_pid=`ps -ef|grep mysqld|grep "$mysql_sock" |grep -vE 'grep|mysqld_safe'|awk '{print $2}'`

if [ "0" = "$mysqld_pid"0 ]
then
            $MYSQL_HOME/bin/mysqld_safe --defaults-file="$mysql_cnf" --user=mysql --datadir="$datadir" --basedir="$MYSQL_HOME" &
            sleep 1
            mysqld_pid=`ps -ef|grep mysqld|grep "$mysql_sock" |grep -vE 'grep|mysqld_safe'|awk '{print $2}'`
            mysqld_pid1="$mysqld_pid"0
            pppct="."
            while  [[ $mysqld_pid1 -lt 1 ]]
            do
                 mysqld_pid=`ps -ef|grep mysqld|grep "$mysql_sock" |grep -vE 'grep|mysqld_safe'|awk '{print $2}'`
                 mysqld_pid1="$mysqld_pid"0
                 if  [ $mysqld_pid1 -gt 1 ]
                 then
                      #clear
                      echo "Starting MySQL$pppct SUCCESS! "
                 else
                      #clear
                      echo "Starting MySQL$pppct"
                 fi
                 pppct="$pppct."
                 sleep 1
            done
else
    echo "A mysqld process already exists ! pid:$mysqld_pid"
fi
}

function stop(){
mysqld_pid=`ps -ef|grep mysqld|grep "$mysql_sock" |grep -vE 'grep|mysqld_safe'|awk '{print $2}'`

if [ "0" = "$mysqld_pid"0 ]
then
   echo "The mysqld process is already stopped ! "
else
#/usr/local/mysql/bin/mysqladmin –S "$mysql_sock" shutdown &
$MYSQL_HOME/bin/mysqladmin  -S "$mysql_sock" shutdown &

sleep 2
mysqld_pid=`ps -ef|grep mysqld|grep "$mysql_sock" |grep -vE 'grep|mysqld_safe'|awk '{print $2}'`
if [ "0" = "$mysqld_pid"0 ]
then
    echo "Stopping MySQL$pppct SUCCESS! "
else
   mysqld_pid1="$mysqld_pid"0
   pppct="."
   while  [ "$mysqld_pid1" != "0" ]
   do
      mysqld_pid=`ps -ef|grep mysqld|grep "$mysql_sock" |grep -vE 'grep|mysqld_safe'|awk '{print $2}'`
      mysqld_pid1="$mysqld_pid"0
      if  [ "$mysqld_pid1" = "0" ]
      then
           #clear
           echo "Stopping MySQL$pppct SUCCESS! "
      else
           #clear
           echo "Stopping MySQL$pppct"
      fi
      pppct="$pppct."
      sleep 1
   done
fi
fi
}

function status(){
mysqld_pid=`ps -ef|grep mysqld|grep "$mysql_sock" |grep -vE 'grep|mysqld_safe'|awk '{print $2}'`

if [ "0" = "$mysqld_pid"0 ]
then
   echo "There is no mysqld process  ! "
else
   echo -e "\n"
   ps -ef|grep mysqld|grep "$mysql_cnf"|grep -v grep
   echo -e "MySQL(pid=$mysqld_pid) Status \n "
   #mysqladmin  -S "$mysql_sock" status  
   $MYSQL_HOME/bin/mysql -S "$mysql_sock"   -e "\s;"
   echo -e "\n"
fi
}

case "$1" in
start)
    start
  ;;
stop)
     stop  
  ;;
status)
       status
  ;;
restart)
       stop
       start
  ;;
*)  
   echo "Usage:sh $0  {start|stop|restart|status}" 
esac
exit

[#11(zhouxx_vm(node3:192.168.56.103))#root@node3~]#
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template