Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1953454
  • 博文数量: 176
  • 博客积分: 1857
  • 博客等级: 上尉
  • 技术积分: 2729
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-14 22:55
个人简介

吾生有涯,而知无涯,适当止学.循序渐进,步步提升 Talk is cheap, show me the code.

文章分类

全部博文(176)

文章存档

2019年(1)

2018年(14)

2017年(20)

2016年(31)

2015年(15)

2014年(5)

2013年(10)

2012年(80)

分类: Mysql/postgreSQL

2012-08-17 18:05:13

[zhangshengdong@forummysql01 ~]$ cat /etc/rc.local(初始化脚本)
#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

/data/mysqldata/3306/mysql start


在写一个启动的shell脚本:
[zhangshengdong@forummysql01 ~]$ cat /data/3306/mysql 
#!/bin/sh

mysql_port=3306
mysql_username="xxx"
mysql_password="xxxxx"

function_start_mysql()
{
    printf "Starting MySQL...\n"
    /bin/sh /usr/local/webserver/mysql/bin/mysqld_safe --defaults-file=/data/${mysql_port}/my.cnf 2>&1 > /dev/null &
}

function_stop_mysql()
{
    printf "Stoping MySQL...\n"
    /usr/local/webserver/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -S /data/${mysql_port}/mysql.sock shutdown
}

function_restart_mysql()
{
    printf "Restarting MySQL...\n"
    function_stop_mysql
    sleep 5
    function_start_mysql
}

function_kill_mysql()
{
    kill -9 $(ps -ef | grep 'bin/mysqld_safe' | grep ${mysql_port} | awk '{printf $2}')
    kill -9 $(ps -ef | grep 'libexec/mysqld' | grep ${mysql_port} | awk '{printf $2}')
}

if [ "$1" = "start" ]; then
    function_start_mysql
elif [ "$1" = "stop" ]; then
    function_stop_mysql
elif [ "$1" = "restart" ]; then
function_restart_mysql
elif [ "$1" = "kill" ]; then
function_kill_mysql
else
    printf "Usage: /data/${mysql_port}/mysql {start|stop|restart|kill}\n"
fi

这样就可以根据linux的启动的时候,启动

阅读(1786) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

lml_12342012-08-18 09:04:06