您的位置:首页 > 数据库 > MySQL

mysql启动服务配置文件编写

2018-01-17 10:41 330 查看
root@debian45:/home/soft# cat /etc/init.d/mysqld
#!/bin/sh
# Copyright Abandoned 1996 TCX DataKonsult AB & Monty Program KB & Detron HB
# This file is public domain and comes with NO WARRANTY of any kind

# MySQL daemon start/stop script.

# Usually this is put in /etc/init.d (at least on machines SYSV R4 based
# systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.
# When this is done the mysql server will be started when the machine is
# started and shut down when the systems goes down.

# Comments to support chkconfig on RedHat Linux
# chkconfig: 2345 64 36
# description: A very fast and reliable SQL database engine.

# Comments to support LSB init script conventions
### BEGIN INIT INFO
# Provides: mysql
# Required-Start: $local_fs $network $remote_fs
# Should-Start: ypbind nscd ldap ntpd xntpd
# Required-Stop: $local_fs $network $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: start and stop MySQL
# Description: MySQL is a very fast and reliable SQL database engine.
### END INIT INFO

# If you install MySQL on some other places than /usr/local/mysql, then you
# have to do one of the following things for this script to work:
#
# - Run this script from within the MySQL installation directory
# - Create a /etc/my.cnf file with the following information:
# [mysqld]
# basedir=
# - Add the above to any other configuration file (for example ~/.my.ini)
# and copy my_print_defaults to /usr/bin
# - Add the path to the mysql-installation-directory to the basedir variable

basedir=/usr/local/mysql/bin #mysql按装位置
datadir=/home/mysql_db #mysql数据存放位置
defaults=/etc/my.cnf #启动指定的配置文件

# Default value, in seconds, afterwhich the script should timeout waiting
# for server start.
# Value here is overriden by value in my.cnf.
# 0 means don't wait at all
# Negative numbers mean to wait indefinitely
service_startup_timeout=900

# Lock directory for RedHat / SuSE.
lockdir='/var/lock/subsys'
lock_file_path="$lockdir/mysql"

#./etc/init.d/functions
function_usage() {
echo "$0 {start|stop|restart|status}"
exit 1
}
[ $# -ne 1 ] && $(function_usage)
function_mysql_start(){
$basedir/mysqld --defaults-file=$defaults & > /dev/null
if [ $? -eq 0 ]; then
sleep 2
echo -e "\033[32m mysqld start success.....\033[0m"
else
sleep 2
echo -e "\033[31m mysqld start failed......\033[0m"
echo -e "\033[31m please mysql is exists \033[0m"
fi
}
function_mysql_stop() {
$basedir/mysqladmin -uroot -p1qaz2wsx shutdown & > /dev/null
if [ $? -eq 0 ]; then
echo -e "\033[32m mysqld stop success......\033[0m"
else
echo -e "\033[31m mysqld stop failed......\033[0m"
echo -e "\033[31m please mysql is exists \033[0m"
fi
}
funtion_mysql_restart(){
function_mysql_stop
sleep 2
function_mysql_start
}
case $1 in
start)
function_mysql_start
;;
stop)
function_mysql_stop
;;
restart)
funtion_mysql_restart
;;
status)
ps -ef |grep mysql|grep -v grep
;;
*)
printf "Usage:$0 {start|stop|restart|status}\n"
esac
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐