{"id":1854,"date":"2017-07-03T09:27:16","date_gmt":"2017-07-03T01:27:16","guid":{"rendered":"http:\/\/1vr.cn\/?p=1854"},"modified":"2017-07-03T09:31:18","modified_gmt":"2017-07-03T01:31:18","slug":"centos%e4%b8%8b%e7%94%a8crontab%e8%ae%be%e7%bd%ae%e8%87%aa%e5%8a%a8%e9%87%8d%e5%90%afmysql%e8%ae%a1%e5%88%922","status":"publish","type":"post","link":"https:\/\/1vr.cn\/?p=1854","title":{"rendered":"CentOS\u4e0b\u7528crontab\u8bbe\u7f6e\u81ea\u52a8\u91cd\u542fMySQL\u8ba1\u5212(2)"},"content":{"rendered":"<p>\u4e4b\u524d\u5199\u4e86\u4e00\u7bc7\u5728\u6bcf\u5929\u51cc\u66682:30\u91cd\u542f\u4e00\u6b21MySQL\u7684\u6587\u7ae0:<a href=\"http:\/\/1vr.cn\/?p=1818\" target=\"_blank\">http:\/\/1vr.cn\/?p=1818<\/a>,\u7528\u4e86\u4e00\u6bb5\u65f6\u95f4\u611f\u89c9\u6ca1\u4ec0\u4e48\u5f02\u5e38,\u4f46\u4eca\u5929\u53c8\u51fa\u73b0\u4e86\u6570\u636e\u5e93\u975e\u6b63\u5e38\u5173\u95ed,\u771f\u662f\u5934\u75bc,\u770b\u4e86\u4e0b\u65e5\u5fd7(\u7ec8\u7aef\u8f93\u5165:tail -f \/var\/log\/mysqld.log),\u65f6\u95f4\u8fd8\u5728\u57282:30\u4e4b\u524d,\u4e0d\u77e5\u9053\u4ec0\u4e48\u5f02\u5e38\u5bfc\u81f4,\u770b\u6765\u6709\u65f6\u95f4\u8fd8\u662f\u8981\u5f7b\u5e95\u67e5\u67e5\u539f\u56e0.<\/p>\n<pre>\r\n170703  0:41:54  InnoDB: Database was not shut down normally!\r\nInnoDB: Starting crash recovery.\r\nInnoDB: Reading tablespace information from the .ibd files...\r\nInnoDB: Restoring possible half-written data pages from the doublewrite\r\nInnoDB: buffer...\r\nInnoDB: Doing recovery: scanned up to log sequence number 0 22991466\r\n170703  0:41:54  InnoDB: Started; log sequence number 0 22991466\r\n170703  0:41:54 [Note] Event Scheduler: Loaded 0 events\r\n170703  0:41:54 [Note] \/usr\/libexec\/mysqld: ready for connections.\r\n<\/pre>\n<p>\u5728\u5f7b\u5e95\u67e5\u5230\u539f\u56e0\u4e4b\u524d\u5148\u6253\u4e2a\u901f\u6548\u9488\u5427,\u627e\u4e86\u4e00\u6bb5bash shell\u811a\u672c,\u5224\u65admysql\u670d\u52a1\u7684\u72b6\u6001,\u5982\u679c\u6ca1\u6709\u8fd0\u884c,\u5219\u91cd\u542fmysql.<\/p>\n<p>\u811a\u672c\u653e\u54ea\u65e0\u6240\u8c13,\u80fd\u627e\u5230\u5c31\u884c,\u7528&#8221;vim \/etc\/checkmysql.sh&#8221;\u521b\u5efa\u4e2a\u65b0\u6587\u4ef6,\u540d\u4e3acheckmysql.sh,\u653e\u5728\u4e86etc\u76ee\u5f55\u4e0b.<\/p>\n<pre>\r\n#!\/bin\/bash\r\npgrep -x mysqld &> \/dev\/null\r\nif [ $? -ne 0 ]\r\nthen\r\necho \"Time: `date` :MySQL is over .\">> \/var\/log\/mysql_messages\r\nservice mysqld start\r\nelse\r\necho \"MySQL server is running.\"\r\nfi\r\n<\/pre>\n<p>\u8f93\u5165&#8221;:wq&#8221;\u4fdd\u5b58\u5e76\u9000\u51fa\u6587\u4ef6,\u6d4b\u8bd5\u4e00\u4e0b\u6587\u4ef6\u6548\u679c,\u4f7f\u7528&#8221;.\/checkmysql.sh&#8221;\u6216\u7edd\u5bf9\u8def\u5f84&#8221;\/etc\/checkmysql.sh&#8221;,\u53ef\u4ee5\u5f53\u524dMysql\u72b6\u6001,\u5982\u5df2\u505c\u6b62,\u90a3\u4e48\u5c1d\u8bd5\u542f\u52a8\u5b83.\u5982\u679c\u811a\u672c\u6587\u4ef6\u6743\u9650\u4e0d\u5bf9,\u6539\u5b83\u6743\u9650\u4e3a655,\u547d\u4ee4\u662f&#8221;chmod -R 655 checkmysql.sh&#8221;.<\/p>\n<p>\u63a5\u4e0b\u6765\u6211\u4eec\u9700\u8981\u5b9a\u65f6\u7684\u6267\u884c\u8fd9\u4e2a\u811a\u672c,\u8ba9\u5b83\u5e2e\u52a9\u6211\u4eec\u76d1\u6d4bmysql\u72b6\u6001.\u8fd8\u662f\u7528\u5230\u4e86crontab,\u4e4b\u524d\u7684\u6587\u7ae0\u91cc\u6709\u6bd4\u8f83\u8be6\u7ec6\u7684\u7528\u6cd5,\u8fd9\u91cc\u7b80\u5355\u8bf4\u660e,\u6211\u8981\u505a\u7684\u662f\u8ba9\u811a\u672c3\u5206\u949f\u6267\u884c\u4e00\u6b21,\u90a3\u4e48\u6253\u5f00crontab\u7f16\u8f91(\u547d\u4ee4:vim \/etc\/crontab):<\/p>\n<p>\u4e95\u53f7\u6ce8\u91ca\u6389\u4e4b\u524d\u7684\u6bcf\u59292:30\u91cd\u542f\u4efb\u52a1,\u6dfb\u52a0\u4e0b\u9762\u8fd9\u6837<\/p>\n<pre>\r\n*\/3 * * * * root \/etc\/checkmysql.sh\r\n<\/pre>\n<p>&#8220;*\/3&#8243;\u4ee3\u8868\u6bcf\u95f4\u9694\u4e09\u5206\u949f\u6267\u884c\u4e00\u6b21,\u5982\u679c\u4f60\u8981\u4e94\u5206\u949f\u6267\u884c\u4e00\u6b21,\u90a3\u5c31\u662f&#8221;*\/5&#8243;\u55bd.<\/p>\n<p>\u4fdd\u5b58\u540e\u91cd\u542fcrontab\u5373\u53ef(\u547d\u4ee4:service crond restart),\u5982\u679c\u4f60\u8981\u6d4b\u8bd5\u6548\u679c,\u53ef\u4ee5service mysqld stop,\u51e0\u5206\u949f\u540e\u770bmysql\u662f\u5426\u81ea\u542f.<\/p>\n<p>\u539f\u521b\u6587\u7ae0,\u8f6c\u8d26\u8bf7\u6ce8\u660e\u6765\u81ea http:\/\/1vr.cn,By XK.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u5199\u4e86\u4e00\u7bc7\u5728\u6bcf\u5929\u51cc\u66682:30\u91cd\u542f\u4e00\u6b21MySQL\u7684\u6587\u7ae0:http:\/\/1vr.cn\/?p=1818,\u7528\u4e86\u4e00\u6bb5\u65f6 &hellip; <a href=\"https:\/\/1vr.cn\/?p=1854\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">CentOS\u4e0b\u7528crontab\u8bbe\u7f6e\u81ea\u52a8\u91cd\u542fMySQL\u8ba1\u5212(2)<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-1854","post","type-post","status-publish","format-standard","hentry","category-5","without-featured-image"],"_links":{"self":[{"href":"https:\/\/1vr.cn\/index.php?rest_route=\/wp\/v2\/posts\/1854","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/1vr.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/1vr.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/1vr.cn\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/1vr.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1854"}],"version-history":[{"count":3,"href":"https:\/\/1vr.cn\/index.php?rest_route=\/wp\/v2\/posts\/1854\/revisions"}],"predecessor-version":[{"id":1857,"href":"https:\/\/1vr.cn\/index.php?rest_route=\/wp\/v2\/posts\/1854\/revisions\/1857"}],"wp:attachment":[{"href":"https:\/\/1vr.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/1vr.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/1vr.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}