In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly introduces the enterprise-level use of shell is how to develop MySQL startup script, the contents of the article are carefully selected and edited by the author, with a certain pertinence, for everyone's reference significance is still relatively great, the following with the author to understand the enterprise-level use of shell is how to develop MySQL startup script bar.
Description
The MySQL startup command is:
/ bin/sh mysqld_safe-- pid-file=$mysqld_pid_file_path 2 > & 1 > / dev/null &
The stop command is:
Mysqld_pid= `cat "$mysqld_pid_file_path" `
If (kill-0 $mysqld_pid 2 > / dev/null)
Then
Kill $mysqld_pid
Sleep 2
Fi
Please finish writing the MySQL startup script
Requirements: implemented with functions, case statements, if statements, etc.
Answer:
[root@db02 scripts] # cat / etc/init.d/oldgirl
#! / bin/bash
# chkconfig: 2345 64 36
# description: MySQL startup
# Author:oldboy
# Blog: http://oldboy.blog.51cto.com
# Time:2017-07-07 09:24:34
# Name:mysqld.sh
# Version:V1.0
# Description:This is a test script.
[- f / etc/init.d/functions] & & source / etc/init.d/functions
Port=3306
User= "root"
Bindir= "/ application/mysql/bin"
Datadir= "/ application/mysql/data"
Mysqld_pid_file_path= "/ application/mysql/ `hostname`.pid"
PATH= "/ sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin"
Export PATH
Return_value=
# Lock directory.
Lockdir='/var/lock/subsys'
Lock_file_path= "$lockdir/mysql"
Log_success_msg () {
Echo "SUCCESS! $@"
}
Log_failure_msg () {
Echo "ERROR! $@"
}
Case "$1" in
Start)
# Start daemon
Echo "Starting MySQL"
If test-x $Bindir/mysqld_safe
Then
Bindir/mysqld_safe-- datadir= "$Datadir"-- pid-file= "$mysqld_pid_file_path" > / dev/null &
Return_value=$?
Sleep 2
# Make lock for CentOS
If test-w "$lockdir"
Then
Touch "$lock_file_path"
Fi
Exit $return_value
Else
Log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)"
Fi
Stop)
If test-s "$mysqld_pid_file_path"
Then
Mysqld_pid= `cat "$mysqld_pid_file_path" `
If (kill-0 $mysqld_pid 2 > / dev/null)
Then
Echo "Shutting down MySQL"
Kill $mysqld_pid
Return_value=$?
Sleep 2
Else
Log_failure_msg "MySQL server process # $mysqld_pid is not running!"
Rm-f "$mysqld_pid_file_path"
Fi
# Delete lock for CentOS
If test-f "$lock_file_path"
Then
Rm-f "$lock_file_path"
Fi
Exit $return_value
Else
Log_failure_msg "MySQL server PID file could not be found!"
Fi
Restart)
If $0 stop; then
$0 start
Else
Log_failure_msg "Failed to stop running server, so refusing to try to start."
Exit 1
Fi
*)
Echo "Usage: $0 {start | stop | restart}"
Exit 1
Esac
Exit $return_value
Function version:
#! / bin/bash
# chkconfig: 2345 64 36
# description: MySQL startup
# Author:oldboy
# Blog: http://oldboy.blog.51cto.com
# Time:2017-07-07 09:24:34
# Name:mysqld.sh
# Version:V1.0
# Description:This is a test script.
[- f / etc/init.d/functions] & & source / etc/init.d/functions
Port=3306
User= "root"
Bindir= "/ application/mysql/bin"
Datadir= "/ application/mysql/data"
Mysqld_pid_file_path= "/ application/mysql/ `hostname`.pid"
PATH= "/ sbin:/usr/sbin:/bin:/usr/bin:$basedir/bin"
Export PATH
Return_value=
# Lock directory.
Lockdir='/var/lock/subsys'
Lock_file_path= "$lockdir/mysql"
Log_success_msg () {
Echo "SUCCESS! $@"
}
Log_failure_msg () {
Echo "ERROR! $@"
}
Start () {
# Start daemon
Echo "Starting MySQL"
If test-x $bindir/mysqld_safe
Then
Bindir/mysqld_safe-- datadir= "$datadir"-- pid-file= "$mysqld_pid_file_path" > / dev/null &
Return_value=$?
Sleep 2
# Make lock for CentOS
If test-w "$lockdir"
Then
Touch "$lock_file_path"
Fi
Exit $return_value
Else
Log_failure_msg "Couldn't find MySQL server ($bindir/mysqld_safe)"
Fi
}
Stop () {
If test-s "$mysqld_pid_file_path"
Then
Mysqld_pid= `cat "$mysqld_pid_file_path" `
If (kill-0 $mysqld_pid 2 > / dev/null)
Then
Echo "Shutting down MySQL"
Kill $mysqld_pid
Return_value=$?
Sleep 2
Else
Log_failure_msg "MySQL server process # $mysqld_pid is not running!"
Rm-f "$mysqld_pid_file_path"
Fi
# Delete lock for CentOS
If test-f "$lock_file_path"
Then
Rm-f "$lock_file_path"
Fi
Exit $return_value
Else
Log_failure_msg "MySQL server PID file could not be found!"
Fi
}
Case "$1" in
Start)
Start
Stop)
Stop
Restart)
If $0 stop; then
$0 start
Else
Log_failure_msg "Failed to stop running server, so refusing to try to start."
Exit 1
Fi
*)
Echo "Usage: $0 {start | stop | restart}"
Exit 1
Esac
Exit $return_value
After reading the above about how the enterprise uses shell to develop MySQL startup scripts, many readers must have some understanding. If you need to get more industry knowledge and information, you can continue to follow our industry information column.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.