Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Operation method of MySQL start and stop script

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

The following to understand the MySQL script operation, I believe that we will benefit a lot after reading, the text in the essence is not much, I hope that the MySQL script operation method of this short content is what you want.

#! / bin/bash

#

Mysqld This shell script takes care of starting and stoppingthe MySQL subsystem (mysqld).

#

Chkconfig: 2345 78 36description: MySQL database server.processname: mysqldconfig: / data/mysql/mysql3306/data/my3306.cnfpidfile: / data/mysql/mysql3306/data/mysql3306.pidSource function library.

. / etc/rc.d/init.d/functions

Source networking configuration.

. / etc/sysconfig/network

Prog= "MySQL"

Extract value of a MySQL option from config filesUsage: get_mysql_option SECTION VARNAME DEFAULTresult is returned in $resultWe use my_print_defaults which prints all options from multiple files,with the more specific ones later; hence take the last match.

Get_mysql_option () {

Result=/usr/local/mysql/bin/my_print_defaults-- defaults-file=/data/mysql/mysql3306/my.cnf "$1" | sed-n "s / ^-- $2pm UniUnip" | tail-n 1

If [- z "$result"]; then

Not found, use default result= "$3" fi

}

Servername=hostname

Get_mysql_option mysqld datadir "/ data/mysql/mysql3306/data/"

Datadir= "$result"

Get_mysql_option mysqld socket "/ data/mysql/mysql3306/data/mysql.sock"

Socketfile= "$result"

Get_mysql_option mysqld log-error "/ data/mysql/mysql3306/data/error.log"

Errlogfile= "$result"

Get_mysql_option mysqld pid-file "/ data/mysql/mysql3306/data/mysql.pid"

Mypidfile= "$result"

Start () {

Touch "$errlogfile"

Chown mysql:mysql "$errlogfile"

Chmod 0640 "$errlogfile"

[- x / sbin/restorecon] & & / sbin/restorecon "$errlogfile"

Pass all the options determined above, to ensure consistent behavior. # In many cases mysqld_safe would arrive at the same conclusions anyway # but we need to be sure. / usr/local/mysql/bin/mysqld_safe-defaults-file=/data/mysql/mysql3306/my.cnf\-user=mysql\ > / dev/null 2 > & 1 & ret=$? # Spin for a maximum of N seconds waiting for the server to come up. # Rather than assuming we know a valid username, accept an "access # denied" response as meaning the server is functioning. If [$ret-eq 0]; then STARTTIMEOUT=30 while [$STARTTIMEOUT-gt 0]; do RESPONSE= `/ usr/local/mysql/bin/mysqladmin-uroot-proot-P3306-h227.0.0.1 ping 2 > & 1` & & break echo "$RESPONSE" | grep-Q "Access denied for user" & & break sleep 1 let STARTTIMEOUT=$ {STARTTIMEOUT}-1 done if [$STARTTIMEOUT-eq 0] Then echo "Timeout error occurred trying to start MySQL Daemon." Action $"Starting $prog:" / bin/false ret=1 else action $"Starting $prog:" / bin/true fi else action $"Starting $prog:" / bin/false fi [$ret-eq 0] & & touch / var/lock/subsys/mysqld return $ret

}

Stop () {

MYSQLPID=cat "$mypidfile" 2 > / dev/null

If [- n "$MYSQLPID"]; then

/ bin/kill "$MYSQLPID" > / dev/null 2 > & 1

Ret=$?

If [$ret-eq 0]; then

STOPTIMEOUT=60

While [$STOPTIMEOUT-gt 0]; do

/ bin/kill-0 "$MYSQLPID" > / dev/null 2 > & 1 | | break

Sleep 1

Let STOPTIMEOUT=$ {STOPTIMEOUT}-1

Done

If [$STOPTIMEOUT-eq 0]; then

Echo "Timeout error occurred trying to stop MySQL Daemon."

Ret=1

Action $"Stopping $prog:" / bin/false

Else

Rm-f / var/lock/subsys/mysqld

Rm-f "$socketfile"

Action $"Stopping $prog:" / bin/true

Fi

Else

Action $"Stopping $prog:" / bin/false

Fi

Else

Ret=1

Action $"Stopping $prog:" / bin/false

Fi

Return $ret

}

Restart () {

Stop

Start

}

Condrestart () {

[- e / var/lock/subsys/mysqld] & & restart | |:

}

See how we were called.

Case "$1" in

Start)

Start

Stop)

Stop

Status)

Status mysqld

Restart)

Restart

Condrestart)

Condrestart

*)

Echo $"Usage: $0 {start | stop | status | condrestart | restart}"

Exit 1

Esac

Exit $?

After reading the MySQL script operation of this article, many readers will want to know more related content, if you need more industry information, you can follow our industry information section.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report