[文章作者:张宴 本文版本: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: , , , ,
技术大类 » 数据库技术 | 评论(110) | 引用(0) | 阅读(53509)
Coach  Outlet Email Homepage
2012-5-19 16:33
Coach Outlet has distribution, product development, and quality control operations in the United States, France, Italy, Japan, Hong Kong, China, and South Korea.Lewis Frankfort has been involved with Coach for more than 30 years.Metro Rail and ICF engineers are working to address this general problem.  The Coach Outlet Canada provides primarily for the Indian Railways, a number of different coaches - first and second class coaches, pantry and kitchen cars, luggage and brake vans, self propelled coaches. 
Coach  Outlet Email Homepage
2012-5-19 16:43
Cashin worked for Coach Outlet from 1962 until 1974, and revolutionized their product design. Known as an innovator, she instituted the inclusion of side pockets, coin purses, and brighter colors onto the bags.In the Coach Outlet Online shop, a collection of high quality and hottest Coach Shoulder Bags is offered to you. They are all at the best prices you will ever find. 
Coach Outlet Online Email Homepage
2012-5-19 16:51
At the Coach Outlet Online Store, quality products and satisfying service are provided;High safety and prompt delivery is guaranteed.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. 
Christian Louboutin Email Homepage
2012-5-19 17:18
christian louboutin have own characteristic designs. The beautiful crystals have added the magical finishing touch to countless bridal gowns. Just get some for yourself. The first Men's Boutique, christian louboutin uk Boutique Homme on Rue Jean-Jacques Rousseau in Paris, opened in the summer of 2012.
Louis Vuitton UK Email Homepage
2012-5-19 17:18
Cheap louis vuitton uk wholesale offers a variety of options to satisfy your needs. Some new ones even has fashionable styles fold over flap to disguise the snap closure and a draw string is added for a convenient closure. Louis vuitton outlet online just like a person who want to show himself in front of other people, because he is confident enough, he can attain the respect of other people.
CoachOutlet Email Homepage
2012-5-19 17:18
coach outlet has become a popular shopping experience for consumers around the world, and a desirable distribution channel for manufacturer's and retailers. Coach outlet online develops very quickly because it runs by its own special way and it contents the customers greatly.
Air Jordan Email Homepage
2012-5-19 17:18
Thank you for shopping in our store. We are a reliable online jordan bags seller, specialist in providing numbers of new air jordan bags at amazing price . If you need practical, fashionable and well-known nike dunks, you can consider to choosing on the nike Outlet. Its nice and popular design will make you feel a sense of fresh air.
Nike Air Max Email Homepage
2012-5-19 17:18
This nike air max for sale belongs to the sounding just what are termed as nike air vintage best sellers, many other products and services for the reason that range appearing companies the actual nike air Galliera, plus the nike air outlet monogram selection. nike dunks are made of high leather materials which can be durable and fashionable.They will make you become the focus in the streets or audience.
xujie123
2012-5-21 11:21
Our online store offers you discounted Designer louis vuitton replica wallet at present. You could find them in desirable quality and price. If you don't mind high class louis vuitton uk, have a good time here.louis vuitton Store Online Handbags can also bring great accuracy as well as practical applicability and fashionable.Have you ever dreamed of being as charming as Madonna? Have you ever thought of becoming an envy of all your friends? If so, come to louis vuitton outlet.<br/>
xujie555
2012-5-21 13:46
coach factory outlet uses graceful accessories to match the classical logo of coach, which is the best combination of coach. The handmade coach products?can make you more charming and graceful.coach factory online provides people many coach goods. If you wish to snatch the coach handbag, then this best method is made for that you like for coach discount.coach factory outlet online is a fashion brand to ensure its quality. With designer coach shoulder bags, you will always attract people's attention. The bags will emphasize your personal style and taste.<br/>
xujie333
2012-5-21 15:10
coach outlet online Store guarantee that all the coach handbags offered are own high quality. In addition , all of them are sold at an unexpected low price.If you want to purchase, just visit their website.coach factory outlet is really sizzling kinds of shopping way for you. With the usage of the replica designer coach bags, you can surely be able to change your individual looks in a stunning manner.Coach bags on sale from the coach outlet are cheap or discount prices that you certainly will stand out from the crowd on your next camping trip!<br/>
coach88888888 Email
2012-8-13 17:51
If you desire to go to Coach Factory Outlet, but have no idea in which to go, you can research online. It is no doubt that there is drastically information and details about it for the reference.Coach Factory Online are loved by many people, when you walk in the street, you could see many people take coach styles.hat experts claim Coach Outlet Online shopping is in the changes they are available in.Coach Outlet will send you a coupon in the post to use in their upon only after you type a achieve. The Coach bags are customarily somewhat many than the ones in the stores.
change Email Homepage
2012-9-13 09:03
et dans la sac chanel pas cher législation des états protestants, la constitution des universités re?oit des changements
univers Email Homepage
2012-9-13 09:04
l'enseignement supra chaussure supérieur; voilà pourquoi ils sont légalement intervenus dans l'organisation universitaire.
eussen Email Homepage
2012-9-13 09:04
à la hiérarchie casque audio beats de l'Eglise, les universités reconnaissaient en elle la seule autorité dont elles eussent
GJHJH Email Homepage
2012-9-26 10:58
Never expose your leather-based handbag Karen Millen below the sunlight for any extended period. this can be simply because the leather-based might be dried out through the warm sunlight.Never allow you leather-based handbag make contact with along with your perfume, entire body spray or any aesthetic fluid etc. and also you might also refrain from the bath lotion or footwear cleanup cream. The mechanised product in both of those people Karen Millen outlet liquids would have transformed the leather-based hence creating it fragile.Protect it from any pointed objects as they, as opposed to the canvas,  will be punched with holes right here and there.Some notes concerning the cleaningDo not thoroughly clean it every single evening but frequently thoroughly clean it. i am aware which you adore your bags pretty much, but cleanup it every single evening would do extra harm than good.Clean the handbag having a item of damp cloth rather than dried out cloth or wet cloth. this can be simply because Karen Millen dress the deficiency of drinking water during the cloth could not assist removing the dirt or stain even though the too much drinking water during the cloth may well permeate in to the bag and mold it.
casque audio beats Email Homepage
2012-10-11 09:08
le droit de chasse et de pêche , casque audio beats ou qu'il l'aurait concédé au preneur: mais dan^ cette dernière hypothèse celui-ci aurait
sac chanel pas cher Email Homepage
2012-10-11 09:09
du do? m aine public , étant assujétis par les lois sac chanel pas cher et arrêts de régle? ment à la dépense du curage et à l'entretien des rivières ? doivent jouir du bénéfice puisqu'ils supportent les chargesCet avis, comme il est facile de le remarquer,
ray ban pas cher Email Homepage
2012-10-11 09:10
l'origine, dont on n'a point payé l? prix , ray ban pas cher  et dont le produit, dans bien des cas , pourrait suffire au fermier pour acquitter le prix de sa location , en sorte qu'il jouirait sans rétribution de tout le reste du domaine utile.Au
canada goose pas cher Email Homepage
2012-10-12 14:04
seulement de dommages canada goose pas cher et intérêts adjugés en matière civile contre une fille; qu'en pareil ctfs, la contrainte par
分页: 2/6 第一页 上页 1 2 3 4 5 6 下页 最后页
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]