{"id":2572,"date":"2018-08-07T09:28:09","date_gmt":"2018-08-07T01:28:09","guid":{"rendered":"https:\/\/www.webteach.tw\/?p=2572"},"modified":"2018-08-07T09:28:09","modified_gmt":"2018-08-07T01:28:09","slug":"%e8%87%aa%e5%8b%95%e9%87%8d%e5%95%9f","status":"publish","type":"post","link":"https:\/\/www.webteach.tw\/?p=2572","title":{"rendered":"[ MySql ] &#8211;  MySql \u505c\u6b62\u5f8c \u81ea\u52d5\u91cd\u555f"},"content":{"rendered":"<p>\t\t\t\t\u5c0f\u7de8\u7684\u7db2\u7ad9\u662f\u67b6\u5728AWS\u4e0a\uff0c\u7528\u7684\u662f\u6700\u4f4e\u968e\u7684\uff1b\u5c0d\u8cc7\u6599\u5eab\u7684\u5b58\u53d6\u5f88\u983b\u7e41\u6240\u4ee5\u5e38\u5e38\u6703\u639b\u6389\uff08\u901a\u5e38\u662f\u6709\u4eba\u5728\u722c\u6211\u7684\u7db2\u7ad9\u6642\uff09\uff0c\u6bcf\u6b21\u90fd\u8981\u767b\u5165\u9060\u7aef\u91cd\u555f\u597d\u9ebb\u7169\uff0c\u5c31\u4e0a\u7db2\u722c\u6587\u4e00\u4e0b\u679c\u7136\u6709\u627e\u5230\u76f8\u95dc\u7684\u7a0b\u5f0f\uff0c\u5c31\u9078\u4e00\u500b\u5beb\u7684\u6700\u7c21\u55ae\u7684\u4f86\u5be6\u4f5c\u3002<!--more--><br \/>\n\u5148\u65b0\u589erestart_mysql.sh\u6a94\uff0c\u8f38\u5165\u4ee5\u4e0b\u6587\u5b57<br \/>\n[php]<br \/>\n#!\/bin\/sh<br \/>\npidof mysqld &gt;\/dev\/null<br \/>\nif [ $? -eq 0 ]<br \/>\nthen<br \/>\necho &quot;At `date` Mysql Server is running.&quot; &gt;&gt; \/home\/mysql_log<br \/>\nelse<br \/>\necho &quot;At `date` Mysql Server was stopped.&quot; &gt;&gt; \/home\/mysql_log<br \/>\nsudo service mysql start<br \/>\nfi<br \/>\n[\/php]<br \/>\n\u7a0b\u5f0f\u78bc\u8aaa\u660e\uff1a<br \/>\n#!\/bin\/sh \u4f7f\u7528shell script<br \/>\npidof \u662f\u67e5\u8a62\u7a0b\u5f0f\u7684pid \u9019\u908a\u5c31\u662f\u5148\u67e5\u8a62mysql\u7684pid<br \/>\nif [ $? -eq 0 ] $?\u8868\u793a\u4e0a\u4e00\u500b\u6307\u4ee4\u56de\u50b3\u7d50\u679c \u901a\u5e38 0\u8868\u793a\u6b63\u5e38\u57f7\u884c\uff0c 1 \u5c31\u8868\u793amysql\u670d\u52d9\u5df2\u505c\u6b62<br \/>\nthen \u7136\u5f8c\u5c31<br \/>\necho &#8220;At `date` Mysql Server is running.&#8221; >> \/home\/mysql_log \u8f38\u51fa mysql \u670d\u52d9\u6b63\u5728\u57f7\u884c\u4e2d \u5beb\u5165 log\u6a94<br \/>\nelse \u4e0d\u7136\u5c31<br \/>\necho &#8220;At `date` Mysql Server was stopped.&#8221; >> \/home\/mysql_log \u8f38\u51fa mysql \u670d\u52d9\u5df2\u505c\u6b62 \u5beb\u5165 log<br \/>\nsudo service mysql start \u4f7f\u7528root\u6b0a\u9650 \u91cd\u65b0\u555f\u52d5 mysql<br \/>\nfi \u689d\u4ef6\u5f0f\u7d50\u5c3e<br \/>\n\u5beb\u5b8c\u5f8c\u5148\u57f7\u884c\u6e2c\u8a66\u4e00\u4e0b\u770b\u6709\u6c92\u6709\u6b63\u78ba\u57f7\u884c<br \/>\n\u5148\u770b\u4e00\u4e0b\u76ee\u524d\u7684mysql\u662f\u5426\u6709\u9032\u7a0bid<br \/>\n  \u6307\u4ee4\uff1apidof mysqld \u986f\u793a\u7d50\u679c\u6703\u662f\u4e00\u4e32\u6578\u5b57 ex 960<br \/>\n\u7136\u5f8c\u505c\u7528mysql<br \/>\n  \u6307\u4ee4\uff1aservice mysql stop<br \/>\n\u518d\u5c07 restart_mysql.sh \u8b8a\u66f4\u6b0a\u9650 \uff08\u9019\u4e00\u6b65\u662f\u70ba\u4e86\u8b93\u6392\u7a0b\u53ef\u4ee5\u57f7\u884c\uff09<br \/>\n  \u6307\u4ee4\uff1achmod 777 restart_mysql.sh<br \/>\n\u5728\u4e0b\u6307\u4ee4\u6e2c\u8a66\u4e00\u4e0b<br \/>\n  \u6307\u4ee4\uff1ash restart_mysql.sh<br \/>\n\u5982\u679c\u6b63\u78ba\u57f7\u884c mysql_log\u6a94\u6703\u986f\u793a At \u5e74\u6708\u65e5 Mysql Server was stopped.<br \/>\n\u7136\u5f8cmysql\u6703\u88ab\u91cd\u65b0\u555f\u52d5<br \/>\n\u6700\u5f8c\u5c31\u5c07\u4e0a\u9762\u7684\u7a0b\u5f0f\u52a0\u5165\u6392\u7a0b<br \/>\n\u6307\u4ee4\uff1acrontab -e<br \/>\n\u52a0\u5165\u4e0b\u9762\u9019\u884c \uff08\u6bcf\u4e94\u5206\u9418\u5224\u65b7mysql\u57f7\u884c\u72c0\u614b\uff09<br \/>\n*\/5 * * * * sh \/home\/restart_mysql.sh<br \/>\n\u53c3\u8003\u8cc7\u6599\uff1a<br \/>\n<a href=\"https:\/\/www.bennythink.com\/cron-mysql-autorestart.html\" rel=\"noopener noreferrer\" target=\"_blank\">https:\/\/www.bennythink.com\/cron-mysql-autorestart.html<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5c0f\u7de8\u7684\u7db2\u7ad9\u662f\u67b6\u5728AWS\u4e0a\uff0c\u7528\u7684\u662f\u6700\u4f4e\u968e\u7684\uff1b\u5c0d\u8cc7\u6599\u5eab&#8230;<\/p>\n","protected":false},"author":1,"featured_media":1867,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[32,34],"tags":[402,1131],"class_list":["post-2572","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-linux","category-mysql","tag-mysql","tag-1131","hvn-theme-has-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/2572","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2572"}],"version-history":[{"count":0,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/2572\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/media\/1867"}],"wp:attachment":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2572"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2572"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2572"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}