mysql服务配置文件_mysql启动服务配置文件编写

[email protected]:/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

原文:http://blog.51cto.com/9025736/2061889

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值