{"id":1004,"date":"2009-11-26T11:11:41","date_gmt":"2009-11-26T03:11:41","guid":{"rendered":"http:\/\/orczhou.com\/?p=1004"},"modified":"2009-12-02T19:42:08","modified_gmt":"2009-12-02T11:42:08","slug":"mysqldauto","status":"publish","type":"post","link":"https:\/\/www.orczhou.com\/index.php\/2009\/11\/mysqldauto\/","title":{"rendered":"mysqld\u968fLinux\u5f00\u673a\u81ea\u52a8\u542f\u52a8"},"content":{"rendered":"<p>\u5728MySQL\u7684\u7ba1\u7406\u8fc7\u7a0b\u4e2d\uff0c\u5076\u5c14\u4f1a\u9047\u5230\u4e00\u4e9bPC Server\u5b95\u673a\u6216\u8005\u91cd\u542f\uff0c\u8fd9\u65f6\u6211\u9700\u8981\u5728\u4e3b\u673a\u542f\u52a8\u540e\u518d\u5c06MySQL\u670d\u52a1\u542f\u52a8\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u8fd9\u9879\u5de5\u4f5c\u90fd\u662f\u7b80\u5355\u7684\u3002\u4f46\u662f\uff0c\u5f53\u9762\u4e34\u4e0a\u767e\u53f0\u6216\u8005\u66f4\u591a\u7684MySQL\u4e3b\u673a\u7684\u65f6\u5019\uff0c\u8fd9\u79cd\u201c\u5076\u5c14\u201d\u53ef\u80fd\u4f1a\u5f88\u591a\uff0c\u8fd9\u79cd\u201c\u5076\u5c14\u201d\u8fd8\u4f1a\u5728\u534a\u591c\u6216\u8005\u51cc\u6668\u53d1\u751f\uff0c\u5982\u679c\u6bcf\u6b21\u90fd\u624b\u52a8\u64cd\u4f5c\uff0c\u8fd9\u662f\u5f88\u7e41\u7410\u7684\u3002\u66f4\u91cd\u8981\u7684\u662f\uff0c\u5982\u679c\u56e0\u6b64\u800c\u6253\u65ad\u4e86\u51cc\u6668\u7684\u7f8e\u68a6\u662f\u4e0d\u503c\u5f97\u7684\u3002<\/p>\n<p><a href=\"http:\/\/www.flickr.com\/photos\/26825745@N06\/4132795867\/\" title=\"LinuxMySQL-2 by orczhou, on Flickr\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/farm3.static.flickr.com\/2660\/4132795867_0e8c895ca4_o.png\" width=\"341\" height=\"268\" alt=\"LinuxMySQL-2\" \/><\/a><\/p>\n<p><!--more--><\/p>\n<p>\u8981\u5b9e\u73b0\u968f\u5f00\u542f\u81ea\u52a8\u542f\u52a8mysqld\uff0c\u6211\u4eec\u9700\u8981\u641e\u5b9a\u5982\u4e0b\u51e0\u4e2a\u95ee\u9898\uff1a<\/p>\n<p><font color=\"red\">1. Linux\u5f00\u673a\u81ea\u52a8\u542f\u52a8\u811a\u672c\u653e\u5728\u54ea\u513f\uff1f<\/font> <\/p>\n<p>\u4e00\u822c\u7684\uff0c\u4f5c\u4e3a\u670d\u52a1\u5668\u4f7f\u7528\u7684Linux\u4e00\u822c\u4f1a\u4ee5\u201c\u5b8c\u5168\u591a\u7528\u6237\u6a21\u5f0f(Multi-User Mode with Networking)\u201d\u7ea7\u522b\u6765\u542f\u52a8\uff0c\u8fd9\u79cd\u60c5\u51b5\u4e0bLinux\u5728\u542f\u52a8\u65f6\u4f1a\u8fd0\u884c\/etc\/rc.d\/rc3.d\/\u4e0b\u7684\u5168\u90e8\u811a\u672c\u3002\u4f8b\u5982\u6211\u4eec\u5728\u8fd9\u4e2a\u76ee\u5f55\u4e0b\u4f1a\u770b\u5230\u811a\u672c&#8221;\/etc\/rc.d\/rc3.d\/S90crond&#8221;\uff0c\u610f\u5473\u7740\u5f00\u673a\u542f\u52a8\u65f6\u4f1a\u8fd0\u884cS90crond\u811a\u672c\u3002<\/p>\n<p><font color=\"red\">2. Linux\u5982\u4f55\u8fd0\u884c\u8fd9\u4e9b\u811a\u672c\uff1f<\/font> <\/p>\n<p>\u65e2\u7136\u5df2\u7ecf\u77e5\u9053\u81ea\u52a8\u542f\u52a8\u811a\u672c\u8be5\u653e\u5728\u54ea\u513f\u4e86\uff0c\u4e00\u5207\u5c31\u597d\u529e\u3002\u6211\u4eec\u53ea\u9700\u8981\u5c06\u4e00\u4e2a\u542f\u52a8MySQL\u7684\u811a\u672c\u653e\u8fc7\u53bb\u5c31\u597d\u4e86\u3002\u4e0b\u9762\u662f\u6211\u4eec\u7684\u4e00\u4e2a\u7b80\u5355\u7684\u542f\u52a8\u811a\u672cv0.1 mysqldauto<\/p>\n<div class=\"mycode\">\n$vi mysqldauto<br \/>\n#!\/bin\/sh<br \/>\n# Version: 0.1 by orczhou@gmail.com<br \/>\n\/opt\/mysql\/bin\/mysqld_safe &#8211;user=mysql &#038;      #\u8fd9\u91cc\u9700\u8981\u4fee\u6539\u4e3a\u4f60\u7684mysqld_safe\u76ee\u5f55<br \/>\n$chmod +x mysqldauto<br \/>\n$mv mysqldauto \/etc\/rc.d\/init.d\/<br \/>\n$ln -s \/etc\/rc.d\/init.d\/mysqldauto \/etc\/rc.d\/rc3.d\/S99mysqld\n<\/div>\n<p>\u8fd9\u6837\u6211\u4eec\u5c31\u628a\u521b\u5efa\u7684mysqldauto\u811a\u672c\u653e\u5230\u4e86\/etc\/rc.d\/rc3.d\/\u4e0b\u9762\uff08\u6ce8\u610f\u8fd9\u91cc\u4f7f\u7528\u4e86link\u7684\u65b9\u5f0f\uff09\uff0cmysqld\u53ef\u4ee5\u81ea\u52a8\u542f\u52a8\u4e86\u3002<\/p>\n<p>\u8fd9\u6709\u4e24\u4e2a\u95ee\u9898\u9700\u8981\u89e3\u91ca\uff1a<\/p>\n<p>* <font color=\"red\"> * <\/font>* <font color=\"red\">*<\/font> * \u4e3a\u4ec0\u4e48\u4e0d\u76f4\u63a5\u5728\u76ee\u5f55\/etc\/rc.d\/rc3.d\/\u4e0b\u521b\u5efa\u6587\u4ef6\uff0c\u800c\u8981\u521b\u5efa\u4e00\u4e2a\u8f6f\u8fde\u63a5\uff1f\u8fd9\u5e76\u4e0d\u662f\u5fc5\u987b\u7684\u3002\u4f46\u662f\u8fd9\u6837\u505a\u662f\u6709\u5f88\u591a\u597d\u5904\u7684\uff08\u540e\u9762\u4f1a\u89e3\u91ca\uff09\uff0c\u4e0d\u8fc7\u8fd9\u6837\u505a\u81f3\u5c11\u4f1a\u770b\u8d77\u6765\u66f4\u52a0\u4e13\u4e1a\u3002<\/p>\n<p>* <font color=\"red\"> * <\/font>* <font color=\"red\">*<\/font> * \u4e3a\u4ec0\u4e48\u6587\u4ef6\u540d\u8981\u7528S99mysqld\uff1f\u8fd9\u662f\u89c4\u5219\uff0c\u5728rc3.d\u4e0b\u9762\u7684\u811a\u672c\u5982\u679c\u4ee5\u5b57\u6bcdS\u5f00\u5934\uff0c\u90a3\u4e48\u6267\u884c\u65f6Linux\u4f1a\u7ed9\u5b83\u4f20\u9012\u4e00\u4e2astart\u53c2\u6570\uff08\u5982\u679c\u4ee5\u5b57\u6bcdK\u5f00\u5934\uff0c\u5219\u4f1a\u4f20\u9012stop\u53c2\u6570\uff09\uff1bS\u540e\u9762\u63a5\u4e2a\u6570\u5b57\uff0c\u8868\u793a\u4e86\u8fd9\u4e2a\u811a\u672c\u7684\u542f\u52a8\u987a\u5e8f\uff0c\u5982\u679c\u76ee\u5f55rc3.d\u4e0b\u8fd8\u6709S98*\u90a3\u4e48\u5b83\u4f1a\u5728S99\u4e4b\u524d\u8fd0\u884c\u3002\uff08\u770b\u5230\u8fd9\u513f\uff0c\u4f60\u53ef\u4ee5\u731c\u6d4b\u4e00\u4e0b\u524d\u9762\u6211\u4eec\u4e3a\u4ec0\u4e48\u8981\u521b\u5efa\u8f6f\u8fde\u63a5\u4e86\uff09<\/p>\n<p>\u597d\u4e86\uff0c\u81ea\u6b64\u4f60\u7684mysqld\u5c31\u5df2\u7ecf\u53ef\u4ee5\u968fLinux\u5f00\u673a\u81ea\u52a8\u542f\u52a8\u4e86\u3002<\/p>\n<p><font color=\"red\">3. \u600e\u6837\u505a\u66f4\u4e13\u4e1a\u4e9b\uff1f<\/font> <\/p>\n<p>\u4e0a\u9762\u8fd9\u6837\u505a\uff0c\u5df2\u7ecf\u53ef\u4ee5\u89e3\u51b3\u95ee\u9898\u4e86\uff0c\u4e0d\u8fc7\u5199\u6cd5\u591a\u5c11\u6709\u4e9b\u201c\u5c71\u5be8\u201d\uff0c\u4e0b\u9762\u6211\u4eec\u770b\u770b\u600e\u6837\u6539\u9020\u4e00\u4e0b\u3002<\/p>\n<p>* <font color=\"red\"> * <\/font>* <font color=\"red\">*<\/font> * \u6539\u90201\uff1a\u5904\u7406\u53c2\u6570start\u3002\u65e2\u7136\u524d\u9762\u63d0\u5230\u4ee5\u5b57\u6bcdS\u5f00\u5934\u7684\u811a\u672c\u4f1a\u81ea\u52a8\u4f20\u9012\u4e00\u4e2a\u53c2\u6570start\uff0cK\u5219\u4f1a\u4f20\u9012stop\u3002\u90a3\u4e48\u6211\u518d\u505a\u5982\u4e0b\u4fee\u6539\uff1a<\/p>\n<pre><div class=\"mycode\">\r\n$vi mysqldauto \r\n#!\/bin\/sh\r\n# Version: 0.2 by orczhou@gmail.com\r\nMYSQLHOME=\/opt\/mysql                         #\u8fd9\u91cc\u9700\u8981\u4fee\u6539\u4e3a\u4f60\u7684mysql\u5b89\u88c5\u76ee\u5f55\r\nif [ $# -ge 1 ];then\r\n        mysqldProc=`ps -ef|grep -E \"mysqld.+safe\"|grep -v \"grep\"|wc -l`\r\n        if [ $1 = \"stop\" ] ;then \r\n                if [ $mysqldProc -eq 1 ];then\r\n                        $MYSQLHOME\/bin\/mysqladmin -uroot shutdown\r\n\tfi\r\n        elif [ $1 = \"start\" ];then\r\n                if [ $mysqldProc -eq 0 ];then\r\n                        $MYSQLHOME\/bin\/mysqld_safe --user=mysql &\r\n\t        fi\r\n        fi\r\nfi\r\n\r\n<\/div><\/pre>\n<p>\u505a\u4e86\u5982\u6b64\u6539\u9020\u540e\uff0c\u6211\u4eec\u811a\u672c\u9700\u8981\u63a5\u6536\u4e24\u4e2a\u53c2\u6570start stop\u4e86\u3002\u5982\u679c\u4f60\u60f3\u8ba9\u4f60mysqld\u5728\u5173\u95ed\u4e3b\u673a\u7684\u65f6\u5019\u81ea\u52a8\u5173\u95ed\uff0c\u90a3\u4e48stop\u53c2\u6570\u5c31\u53ef\u4ee5\u8d77\u4f5c\u7528\u4e86\uff1a<\/p>\n<div class=\"mycode\">\n$ln -s \/etc\/rc.d\/init.d\/mysqldauto \/etc\/rc.d\/rc0.d\/K20mysqld\n<\/div>\n<p>\u8fd9\u91cc\u505a\u8f6f\u8fde\u63a5\u597d\u5904\u5c31\u4f53\u73b0\u51fa\u6765\u4e86\uff0c\u542f\u52a8\u548c\u5173\u95ed\u53ea\u9700\u8981\u7528\u4e00\u4e2a\u811a\u672c\u5c31\u53ef\u4ee5\u4e86\u3002<\/p>\n<p>* <font color=\"red\"> * <\/font>* <font color=\"red\">*<\/font> * \u6539\u90202\uff1a\u5f53\u4f60\u9762\u4e34\u51e0\u5341\u4e0a\u767e\u53f0\u4e3b\u673a\u7684\u65f6\u5019\uff0cMySQL\u7684\u542f\u52a8\u53c2\u6570\u53ef\u80fd\u4f1a\u4e0d\u4e00\u6837\uff0c\u4f8b\u5982\u5907\u5e93\u542f\u52a8\u65f6\u53ef\u80fd\u9700\u8981mysqld_safe &#8211;user=mysql &#8211;read_olny=1 &#038;\uff0c\u8fd9\u79cd\u60c5\u51b5\u600e\u4e48\u529e\u5462\uff1f\u8fd9\u91cc\u63d0\u4f9b\u4e00\u4e2a\u89e3\u51b3\u601d\u8def\u3002<\/p>\n<p>\u5728\u4e3b\u673a\u4e0a\u8fd0\u884c\u4e00\u4e2a\u811a\u672c\uff0c\u63a2\u6d4b\u5f53\u524dmysqld\u7684\u542f\u52a8\u53c2\u6570\uff0c\u7136\u540e\u5199\u5230\u4e00\u4e2a\u6307\u5b9a\u7684\u6587\u4ef6\u91cc\u3002\u6700\u540e\uff0c\u5728\u4f60\u7684\u542f\u52a8\u811a\u672c\u4e2d\uff0c\u8bfb\u53d6\u8fd9\u4e2a\u6587\u4ef6\u91cc\u9762\u7684\u542f\u52a8\u53c2\u6570\u6765\u542f\u52a8mysqld\u3002It works\u3002<\/p>\n<p>\u6700\u540e\uff0c\u795d\u4f60\u7761\u4e2a\u597d\u89c9\uff0c\u505a\u4e2a\u597d\u68a6\u3002<\/p>\n<p>\uff08\u5168\u6587\u5b8c\uff09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728MySQL\u7684\u7ba1\u7406\u8fc7\u7a0b\u4e2d\uff0c\u5076\u5c14\u4f1a\u9047\u5230\u4e00\u4e9bPC Server\u5b95\u673a\u6216\u8005\u91cd\u542f\uff0c\u8fd9\u65f6\u6211\u9700\u8981\u5728\u4e3b\u673a\u542f\u52a8\u540e\u518d\u5c06MySQL\u670d\u52a1\u542f\u52a8\u3002\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u8fd9\u9879\u5de5\u4f5c\u90fd\u662f\u7b80\u5355\u7684\u3002\u4f46\u662f\uff0c\u5f53\u9762\u4e34\u4e0a\u767e\u53f0\u6216\u8005\u66f4\u591a\u7684MySQL\u4e3b\u673a\u7684\u65f6\u5019\uff0c\u8fd9\u79cd\u201c\u5076\u5c14\u201d\u53ef\u80fd\u4f1a\u5f88\u591a\uff0c\u8fd9\u79cd\u201c\u5076\u5c14\u201d\u8fd8\u4f1a\u5728\u534a\u591c\u6216\u8005\u51cc\u6668\u53d1\u751f\uff0c\u5982\u679c\u6bcf\u6b21\u90fd\u624b\u52a8\u64cd\u4f5c\uff0c\u8fd9\u662f\u5f88\u7e41\u7410\u7684\u3002\u66f4\u91cd\u8981\u7684\u662f\uff0c\u5982\u679c\u56e0\u6b64\u800c\u6253\u65ad\u4e86\u51cc\u6668\u7684\u7f8e\u68a6\u662f\u4e0d\u503c\u5f97\u7684\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","inline_featured_image":false,"_tocer_settings":[],"footnotes":""},"categories":[6,4],"tags":[121,118],"class_list":["post-1004","post","type-post","status-publish","format-standard","hentry","category-mysql","category-code-detail","tag-linux","tag-mysql"],"_links":{"self":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/1004","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/comments?post=1004"}],"version-history":[{"count":27,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/1004\/revisions"}],"predecessor-version":[{"id":1029,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/1004\/revisions\/1029"}],"wp:attachment":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/media?parent=1004"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/categories?post=1004"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/tags?post=1004"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}