{"id":43642,"date":"2024-10-06T01:37:33","date_gmt":"2024-10-05T17:37:33","guid":{"rendered":"https:\/\/server.hk\/cnblog\/43642\/"},"modified":"2024-10-06T01:37:33","modified_gmt":"2024-10-05T17:37:33","slug":"centos-7-mysql-%e5%ae%88%e8%ad%b7%ef%bc%88%e5%ae%9a%e6%99%82%e6%aa%a2%e6%b8%ac-mysql-%e9%81%8b%e8%a1%8c%e7%8b%80%e6%85%8b%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/43642\/","title":{"rendered":"CentOS 7 mysql \u5b88\u8b77\uff08\u5b9a\u6642\u6aa2\u6e2c mysql \u904b\u884c\u72c0\u614b\uff09"},"content":{"rendered":"<h1 id=\"centos-7-mysql-%e5%ae%88%e8%ad%b7%ef%bc%88%e5%ae%9a%e6%99%82%e6%aa%a2%e6%b8%ac-mysql-%e9%81%8b%e8%a1%8c%e7%8b%80%e6%85%8b%ef%bc%89-wGOZLQIyhV\">CentOS 7 MySQL \u5b88\u8b77\uff08\u5b9a\u6642\u6aa2\u6e2c MySQL \u904b\u884c\u72c0\u614b\uff09<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u64da\u9a45\u52d5\u4e16\u754c\u4e2d\uff0cMySQL \u4f5c\u70ba\u4e00\u500b\u6d41\u884c\u7684\u958b\u6e90\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u61c9\u7528\u7a0b\u5e8f\u548c\u7db2\u7ad9\u3002\u5c0d\u65bc\u4f7f\u7528 CentOS 7 \u7684\u4f3a\u670d\u5668\u7ba1\u7406\u54e1\u4f86\u8aaa\uff0c\u78ba\u4fdd MySQL \u7684\u7a69\u5b9a\u904b\u884c\u81f3\u95dc\u91cd\u8981\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5728 CentOS 7 \u4e0a\u8a2d\u7f6e\u4e00\u500b\u5b88\u8b77\u9032\u7a0b\uff0c\u5b9a\u6642\u6aa2\u6e2c MySQL \u7684\u904b\u884c\u72c0\u614b\uff0c\u4e26\u5728\u767c\u73fe\u554f\u984c\u6642\u81ea\u52d5\u91cd\u555f\u670d\u52d9\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e5%ae%9a%e6%99%82%e6%aa%a2%e6%b8%ac-mysql-%e7%9a%84%e9%81%8b%e8%a1%8c%e7%8b%80%e6%85%8b%ef%bc%9f-wGOZLQIyhV\">\u70ba\u4ec0\u9ebc\u9700\u8981\u5b9a\u6642\u6aa2\u6e2c MySQL \u7684\u904b\u884c\u72c0\u614b\uff1f<\/h2>\n<p>MySQL \u670d\u52d9\u7684\u4e2d\u65b7\u53ef\u80fd\u6703\u5c0e\u81f4\u61c9\u7528\u7a0b\u5e8f\u7121\u6cd5\u8a2a\u554f\u6578\u64da\uff0c\u5f9e\u800c\u5f71\u97ff\u7528\u6236\u9ad4\u9a57\u548c\u696d\u52d9\u904b\u71df\u3002\u5b9a\u6642\u6aa2\u6e2c MySQL \u7684\u904b\u884c\u72c0\u614b\u53ef\u4ee5\u53ca\u65e9\u767c\u73fe\u554f\u984c\uff0c\u4e26\u81ea\u52d5\u8655\u7406\uff0c\u5f9e\u800c\u6e1b\u5c11\u505c\u6a5f\u6642\u9593\u3002\u9019\u5c0d\u65bc\u9700\u8981\u9ad8\u53ef\u7528\u6027\u7684\u61c9\u7528\u7a0b\u5e8f\u5c24\u70ba\u91cd\u8981\u3002<\/p>\n<h2 id=\"%e8%a8%ad%e7%bd%ae-mysql-%e7%9b%a3%e6%8e%a7%e8%85%b3%e6%9c%ac-wGOZLQIyhV\">\u8a2d\u7f6e MySQL \u76e3\u63a7\u8173\u672c<\/h2>\n<p>\u9996\u5148\uff0c\u6211\u5011\u9700\u8981\u7de8\u5beb\u4e00\u500b\u7c21\u55ae\u7684 Bash \u8173\u672c\u4f86\u6aa2\u67e5 MySQL \u7684\u904b\u884c\u72c0\u614b\u3002\u4ee5\u4e0b\u662f\u793a\u4f8b\u8173\u672c\uff1a<\/p>\n<pre><code>#!\/bin\/bash\n\n# \u6aa2\u67e5 MySQL \u662f\u5426\u904b\u884c\nif ! systemctl is-active --quiet mysqld; then\n    echo \"MySQL \u670d\u52d9\u672a\u904b\u884c\uff0c\u6b63\u5728\u91cd\u555f...\"\n    systemctl start mysqld\n    if systemctl is-active --quiet mysqld; then\n        echo \"MySQL \u670d\u52d9\u5df2\u6210\u529f\u91cd\u555f\u3002\"\n    else\n        echo \"\u7121\u6cd5\u91cd\u555f MySQL \u670d\u52d9\uff0c\u8acb\u6aa2\u67e5\u65e5\u8a8c\u3002\"\n    fi\nelse\n    echo \"MySQL \u670d\u52d9\u6b63\u5728\u904b\u884c\u3002\"\nfi\n<\/code><\/pre>\n<p>\u5c07\u4e0a\u8ff0\u4ee3\u78bc\u4fdd\u5b58\u70ba\u540d\u70ba <code>check_mysql.sh<\/code> \u7684\u6587\u4ef6\uff0c\u4e26\u78ba\u4fdd\u5b83\u5177\u6709\u53ef\u57f7\u884c\u6b0a\u9650\uff1a<\/p>\n<pre><code>chmod +x check_mysql.sh<\/code><\/pre>\n<h2 id=\"%e8%a8%ad%e7%bd%ae%e5%ae%9a%e6%99%82%e4%bb%bb%e5%8b%99-wGOZLQIyhV\">\u8a2d\u7f6e\u5b9a\u6642\u4efb\u52d9<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u4f7f\u7528 cron \u4f86\u5b9a\u671f\u57f7\u884c\u9019\u500b\u8173\u672c\u3002\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u7de8\u8f2f cron \u4efb\u52d9\uff1a<\/p>\n<pre><code>crontab -e<\/code><\/pre>\n<p>\u5728\u6253\u958b\u7684\u7de8\u8f2f\u5668\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u884c\u4ee5\u6bcf\u4e94\u5206\u9418\u57f7\u884c\u4e00\u6b21\u6aa2\u67e5\u8173\u672c\uff1a<\/p>\n<pre><code>*\/5 * * * * \/path\/to\/check_mysql.sh<\/code><\/pre>\n<p>\u8acb\u5c07 <code>\/path\/to\/check_mysql.sh<\/code> \u66ff\u63db\u70ba\u5be6\u969b\u8173\u672c\u7684\u8def\u5f91\u3002\u4fdd\u5b58\u4e26\u9000\u51fa\u7de8\u8f2f\u5668\u5f8c\uff0ccron \u5c07\u81ea\u52d5\u958b\u59cb\u904b\u884c\u9019\u500b\u4efb\u52d9\u3002<\/p>\n<h2 id=\"%e6%aa%a2%e6%9f%a5-mysql-%e6%97%a5%e8%aa%8c-wGOZLQIyhV\">\u6aa2\u67e5 MySQL \u65e5\u8a8c<\/h2>\n<p>\u5728\u81ea\u52d5\u91cd\u555f MySQL \u670d\u52d9\u7684\u904e\u7a0b\u4e2d\uff0c\u6aa2\u67e5\u65e5\u8a8c\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002MySQL \u7684\u65e5\u8a8c\u6587\u4ef6\u901a\u5e38\u4f4d\u65bc <code>\/var\/log\/mysqld.log<\/code>\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u65e5\u8a8c\uff1a<\/p>\n<pre><code>tail -f \/var\/log\/mysqld.log<\/code><\/pre>\n<p>\u9019\u6a23\u53ef\u4ee5\u5be6\u6642\u76e3\u63a7 MySQL \u7684\u904b\u884c\u72c0\u614b\uff0c\u4e26\u53ca\u6642\u767c\u73fe\u6f5b\u5728\u7684\u554f\u984c\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-wGOZLQIyhV\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u5728 CentOS 7 \u4e0a\u8a2d\u7f6e\u5b9a\u6642\u6aa2\u6e2c MySQL \u7684\u904b\u884c\u72c0\u614b\uff0c\u6211\u5011\u53ef\u4ee5\u6709\u6548\u5730\u63d0\u9ad8\u6578\u64da\u5eab\u7684\u7a69\u5b9a\u6027\u548c\u53ef\u7528\u6027\u3002\u9019\u4e0d\u50c5\u80fd\u5920\u53ca\u6642\u767c\u73fe\u554f\u984c\uff0c\u9084\u80fd\u81ea\u52d5\u8655\u7406\u670d\u52d9\u4e2d\u65b7\u7684\u60c5\u6cc1\uff0c\u5f9e\u800c\u6e1b\u5c11\u696d\u52d9\u640d\u5931\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u53ef\u7528\u6027\u7684\u61c9\u7528\u7a0b\u5e8f\uff0c\u9019\u662f\u4e00\u500b\u4e0d\u53ef\u6216\u7f3a\u7684\u6b65\u9a5f\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u904b\u884c\u60a8\u7684 MySQL \u6578\u64da\u5eab\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u7684\u5ba2\u6236\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a> \u9084\u662f\u5176\u4ed6\u5730\u5340\u7684\u670d\u52d9\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b9a\u6642\u6aa2\u6e2c CentOS 7 \u4e0a MySQL \u904b\u884c\u72c0\u614b\u7684\u5b88\u8b77\u7a0b\u5e8f\uff0c\u78ba\u4fdd\u6578\u64da\u5eab\u7a69\u5b9a\u904b\u884c\uff0c\u53ca\u6642\u767c\u73fe\u4e26\u89e3\u6c7a\u554f\u984c\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-43642","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43642","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=43642"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43642\/revisions"}],"predecessor-version":[{"id":43643,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/43642\/revisions\/43643"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=43642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=43642"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=43642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}