[文章作者:张宴 本文版本: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) | 阅读(81358)
zxpxyz
2008-7-24 09:59
case "$1" in
 start)
       function_start_mysql
       ;;
 stop)
       function_stop_mysql
       ;;
 restart)
       function_restart_mysql
       ;;
 *)
       echo $"Usage: $0 {start|stop|restart}"
       exit 1
esac

试试改成这样
dd_macle
2008-7-25 14:47
谢谢提供这么好的资料!
weiwei Email Homepage
2008-10-24 17:11
很不错,很实用,赞了

http://bbs.woyool.com
aa Email Homepage
2008-11-17 16:27
感觉kill函数部分有问题, 因为用ps -ef 根本不会显示端口的。 所以你在grep ${mysql_port} 什么结果都没有。谢谢
hey Homepage
2009-2-4 22:26
新年好,祝贵站新年人气更旺!也欢迎来我站逛逛!soittoäänet
louis vuitton uk Email Homepage
2011-11-23 09:03
This louis vuitton uk for sale belongs to the sounding just what are termed as Louis Vuitton vintage best sellers, many other products and services for the reason that range appearing companies.You will easily notice the unfold zippers of this coach outlet store online. That is the decoration. There are some inside pockets for you as well. They are easy to match your clothes and to carry.Let us inspire your inner beauty with fine christian louboutin sale. Purse the elegance in bridal wedding. Enjoy the fashion.
sxcen Homepage
2011-12-28 14:58
谢谢分享
eryi8729 Email Homepage
2011-12-29 20:42
If you want to buy Gucci shoes, be careful in buying because many fake shoes. You must be careful in distinguishing the real and fake shoes,tod's, because is sometimes difficult to distinguish it. Usually it happens on brands such as Gucci,chaussures pas cher, because this brand is one of the most famous labels in the business. To avoid be fooled, you have to learn how to distinguish real and fake shoes.
Here are some tips to distinguish real and fake Gucci shoes:
1. Real Gucci shoes have eight digit serial numbers. You can see it in the inside leather lining of the shoe. In the real Gucci shoes also have stamp “Gucci Made in Italy“. The stamp is located in the heel of the shoe.
2. You should check the little details. Real Gucci shoe soles are made from leather, while the fake Gucci shoes made from synthetic material. If you want to make sure,Converse Pas cher, go to the Gucci store to check out the details of real Gucci shoes.
3. Should pay attention to packaging. Real Gucci shoes packaging usually use a box and a shoe bag. Gucci shoe bags are brown and have logo” G “, the logo is printed in the bag. Gucci shoe box are dark brown with the word ” GUCCI ” and written in silver letters. To make sure, you can look at the official website Gucci or Gucci store.
4. Real Gucci shoes made from high quality leather and very soft material. While the fake Gucci made ​​with cheaper material and rough material. Real Gucci shoes must prone to scuff. Real leather material has a different smell.
5. Gucci shoes are usually expensive. If you buy Gucci shoes at a cheap price so you should be careful to make sure that the shoes are real or fake.

ADVERTISEMENT
puma-online Email Homepage
2012-4-19 10:41
Large discount puma shoes are the main products in puma online store.Just cheap puma schuhe are offered in http://www.puma-online.net site,for we intend to promote our puma outlet by wholesale or retail channel! All puma shoes for men or women are in top quality and with many different sizes.Welcome your visiting!Our puma shoes won good reputation in regular customers.
coach factory outlet Email Homepage
2012-5-17 11:40
Today, following half a century, mentor leather-bases coach factory outlet continues to be the delicate craft of leather-based master is accountable for,Would you like to meet more friends, or go with the times? If yes, coach factory online is opening welcome doors to you.in the market you definitely can find various colorways that are designed in as well as the high quality that applied in. For most of you would like to come. So just come to our coach factory outlet online store to choose one.
louis vuitton sale Email Homepage
2012-5-17 11:40
Louis Vuitton belt at louis vuitton sale is one kind of fashion accessory with high cost performance among the Louis Vuitton accessories.Offering quality LV products with favorable prices, louis vuitton outlet store is at your service. Hurry up, or you can not seize the chance.in fact, louis vuitton is one of the most famous fashion design master.he opened the fist suitcase shop called after his name.
coach outlet online Email Homepage
2012-5-17 11:40
I heard of coach outlet online through the advertisement when I was shopping. And now I often brow the webpage and buy Coach bags online.It is a symbol regarding position not to mention nature.Here I would like to launch a excellent bags pertaining to business men.Which may be coach outlet store.coach outlet has always been simple,durable style features to win consumers.The products are more flexible,with easy bleaching,wear characteristics,and simply use a damp cloth.
coach outlet, Email Homepage
2012-5-17 11:40
Remember the coach outlet provide coach bags which won't be deteriorated into its overall styles by any means. It will maintain its looks, colors, and uniqueness for long time.coach outlet store online has been voted by Hour Detroit magazine readers as the Best of Detroit in their 12th annual readers'poll.Lots of women like which usually amount normally include a coach outlet online ,it provides coziness to many girls that don't even think it is a great bushel of great interest directly to them.
xujie777 Email
2012-5-18 16:38
We aim to make all our customers satisfy with our products. You will find a variety of Men's fashion louis vuitton uk, fashion Women's cheap Louis Vuitton bags in our store at affordable price.Thinking of interesting ways to cost a milestone birthday? louis vuitton online shop had one of the most distinctive distinctive celebrations.bakery along with living room operated by means of about three moment louis vuitton online Most effective Pastry Chef’s of the year Rammy Nominee Chef’s.
xujie777 Email
2012-5-18 16:38
The choices are likely to be basically countless seeing that louis vuitton outlet occurs with the help of completely new and also incredible concepts once in a while.Louis vuitton Wholesale Monogram Canvas HandbagsLouis Vuitton Collection Beach Handbags louis vuitton bags outlet Damier Canvas HandbagsLouis vuitton Mahina HandbagsLouis Vuitton Monogram Mini Lin HandbagsLouis Vuitton Monogram Multicolore HandbagsLouis vuitton Monogram Vernis HandbagsLouis Vuitton Wholesale Epi Leather HandbagsLouis Vuitton For Men HandbagsLouis Vuitton Damier Canvas WalletsLouis Vuitton Epi Leather WalletsLouis Vuitton Monogram Canvas WalletsLouis Vuitton Monogram Vernis WalleLouis Vuitton ShoesLouis Vuitton Men wallets.As the Authentic Louis Vuitton are so high-priced, so came the louis vuitton handbags outlet.
xujie777 Email
2012-5-18 16:38
coach outlet has become a popular shopping experience for consumers around the world, and a desirable distribution channel for manufacturer's and retailers.Getting your hands on coach outlet store online can be a hefty investment of hundreds of dollars.But do not despair,the Coach Outlet store could be the answer to your prayers.coach outlet online is your smart choice when you want to get the discount Coach accessory. You can find the exact Coach Bags and other accessory you want at a low price that's right for you. My dear friends, let the coach outlet online pave your way into the world of high fashion with their ultimate fashion factory.
Louis Vuitton UK Email Homepage
2012-5-19 16:07
Louis Vuitton UK are diversified in various kinds, handbags, backpacks, portable bags, purses, wallets and pouches. All kinds are popular among the whole word people.That publication was the only French periodical to mention the book, Louis Vuitton is the country's biggest advertiser in the press. 
Louis Vuitton Email Homepage
2012-5-19 16:17
During World War II, Louis Vuitton collaborated with the Nazis during the German occupation of France.I know someone has already sent you some photo's of the amazing Marc Jacobs/Louis Vuitton UK exhibition at the Musee Des Arts Decoratifs but I just had to share with you the day I had today . 
分页: 1/7 第一页 1 2 3 4 5 6 7 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]