[文章作者:张宴 本文版本:v1.0 最后修改:2008.07.24 转载请注明原文链接:http://blog.zyan.cc/post/359/]

  写了一个shell脚本,可以在同一台Linux服务器的不同端口,运行多个MySQL服务的情况下,快捷启动、停止、重启、杀死指定端口的MySQL进程。

vi /usr/local/bin/mysql.sh

  输入以下内容(因各服务器的MySQL配置不同,可能需要修改的部分已用红色标注):
#!/bin/sh

mysql_port=$2
mysql_username="root"
mysql_password="123456"

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

function_stop_mysql()
{
    printf "Stoping MySQL...\n"
    /usr/local/mysql/bin/mysqladmin -u ${mysql_username} -p${mysql_password} -h localhost -P ${mysql_port} shutdown
}

function_restart_mysql()
{
    printf "Restarting MySQL...\n"
    function_stop_mysql
    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: mysql.sh {start|stop|restart|kill}\n"
fi


  赋予脚本可执行权限:
chmod +x /usr/local/bin/mysql.sh


  脚本执行方法:
mysql.sh start 3306
mysql.sh stop 3306
mysql.sh restart 3306
mysql.sh kill 3306



Tags: , , , ,



技术大类 » 数据库技术 | 评论(121) | 引用(0) | 阅读(84255)
GAWER
2013-3-5 13:49
买轴承就到:www.jkzhoucheng.cn
Niemts Homepage
2013-3-13 15:26
The uppers bunk Cheap Nike Shox Shoes FUSE technology with serrated shoe covers designed to completely fit the foot, and to help Nike Shox NZ Shoes
you moments best surf trip. The mold collar prevents heel shoes slide and still maintain high Nike Shox R4 Womens stability, even in high-speed running state. Foam midsole is lightweight and flexible, and can be used with air to provide a full range of cushioning protection. Nike Shox NZ Mens The running shoes applied new technology to build for elite athletes, and dynamic support system perfect fusion running shoes highly disruptive innovation and upgrading.[B][/B]
Parloi Email Homepage
2013-3-14 16:58
The uppers bunk Cheap Nike Shox Shoes BLEND technology by using serrated casino shoe tops designed to completely healthy that foot, and to aid you moments Nike Shox NZ Shoes greatest waves trip. That mildew collar prevents back heel shoes and boots slide and nonetheless manage Nike Shox R4 Womens higher stability, even within high-speed running state. Foam midsole is actually lightweight in addition to accommodating, Nike Shox NZ Mens and may end up being combined with atmosphere to deliver a full range connected with padding protection. That operating shoes and boots used fresh technologies to build with regard to snobs athletes, in addition to strong service system excellent blend operating shoes remarkably disruptive advancement and improving.
磨延城 Email Homepage
2013-10-21 21:12
磨途歌学习了
julia1304 Email
2022-6-10 10:03
klondike solitaire game is the most popular classic version of card games. The game goal is to create the four stacks of cards from Ace to King, and each foundation pile in the upper-right corner can only contain one suit.
shz Email
2022-7-2 22:58
I wish more writers of this sort of substance would take the time you did to explore and compose so well. I am exceptionally awed with your vision and knowledge.  Lead generation
shz Email
2022-7-2 23:02
After reading your article I was amazed. I know that you explain it very well. And I hope that other readers will also experience how I feel after reading your article.  Lead generation
shz Email
2022-7-2 23:05
This post is very simple to read and appreciate without leaving any details out. Great work!  Lead generation
shz Email
2022-7-2 23:09
I wish more writers of this sort of substance would take the time you did to explore and compose so well. I am exceptionally awed with your vision and knowledge.  Lead generation
shz Email
2022-7-2 23:17
Great Information sharing .. I am very happy to read this article .. thanks for giving us go through info.Fantastic nice. I appreciate this post.  Lead generation
shz Email
2022-7-2 23:26
this blog was really great, never seen a great blog like this before. i think im gonna share this to my friends..  Lead generation
shzz Email
2022-7-2 23:30
Really appreciate this wonderful post that you have provided for us.Great site and a great topic as well i really get amazed to read this. Its really good.  Lead generation
shz Email
2022-7-2 23:32
Hi to everybody, here everyone is sharing such knowledge, so it’s fastidious to see this site, and I used to visit this blog daily  Lead generation
shzz Email
2022-7-2 23:33
I don’t think many of websites provide this type of information.  Lead generation
Lucky cola
2024-2-7 16:02
Unleash your inner gamer and dominate the virtual realm.  Lucky cola
分页: 6/7 第一页 上页 1 2 3 4 5 6 7 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]