{"id":152401,"date":"2024-11-01T22:43:08","date_gmt":"2024-11-01T14:43:08","guid":{"rendered":"https:\/\/server.hk\/cnblog\/152401\/"},"modified":"2024-11-01T22:43:09","modified_gmt":"2024-11-01T14:43:09","slug":"%e6%b8%ac%e8%a9%a6%e4%bc%ba%e6%9c%8d%e5%99%a8%e9%80%a3%e6%8e%a5%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e6%ad%a5%e9%a9%9f%e8%88%87%e6%96%b9%e6%b3%95%e5%88%86%e4%ba%ab-%e5%a6%82%e4%bd%95%e6%b8%ac%e8%a9%a6","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/152401\/","title":{"rendered":"\u6e2c\u8a66\u4f3a\u670d\u5668\u9023\u63a5\u6578\u64da\u5eab\u7684\u6b65\u9a5f\u8207\u65b9\u6cd5\u5206\u4eab (\u5982\u4f55\u6e2c\u8a66\u4f3a\u670d\u5668\u9023\u63a5\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"%e6%b8%ac%e8%a9%a6%e4%bc%ba%e6%9c%8d%e5%99%a8%e9%80%a3%e6%8e%a5%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e6%ad%a5%e9%a9%9f%e8%88%87%e6%96%b9%e6%b3%95%e5%88%86%e4%ba%ab-cmpZwBRXnF\">\u6e2c\u8a66\u4f3a\u670d\u5668\u9023\u63a5\u6578\u64da\u5eab\u7684\u6b65\u9a5f\u8207\u65b9\u6cd5\u5206\u4eab<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u4f4d\u6642\u4ee3\uff0c\u4f3a\u670d\u5668\u8207\u6578\u64da\u5eab\u4e4b\u9593\u7684\u9023\u63a5\u662f\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5e8f\u904b\u884c\u7684\u57fa\u790e\u3002\u7121\u8ad6\u662f\u958b\u767c\u65b0\u61c9\u7528\u9084\u662f\u7dad\u8b77\u73fe\u6709\u7cfb\u7d71\uff0c\u78ba\u4fdd\u4f3a\u670d\u5668\u80fd\u5920\u6b63\u78ba\u9023\u63a5\u5230\u6578\u64da\u5eab\u90fd\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u672c\u6587\u5c07\u5206\u4eab\u4e00\u4e9b\u6e2c\u8a66\u4f3a\u670d\u5668\u9023\u63a5\u6578\u64da\u5eab\u7684\u6b65\u9a5f\u8207\u65b9\u6cd5\uff0c\u5e6b\u52a9\u60a8\u66f4\u6709\u6548\u5730\u9032\u884c\u9019\u4e00\u904e\u7a0b\u3002<\/p>\n<h2 id=\"1-%e7%a2%ba%e8%aa%8d%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e5%9f%ba%e6%9c%ac%e4%bf%a1%e6%81%af-cmpZwBRXnF\">1. \u78ba\u8a8d\u6578\u64da\u5eab\u7684\u57fa\u672c\u4fe1\u606f<\/h2>\n<p>\u5728\u958b\u59cb\u6e2c\u8a66\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u78ba\u8a8d\u6578\u64da\u5eab\u7684\u57fa\u672c\u4fe1\u606f\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u5eab\u985e\u578b\uff1a<\/strong>\u5982 MySQL\u3001PostgreSQL\u3001MongoDB \u7b49\u3002<\/li>\n<li><strong>\u4e3b\u6a5f\u5730\u5740\uff1a<\/strong>\u6578\u64da\u5eab\u6240\u5728\u7684\u4f3a\u670d\u5668 IP \u5730\u5740\u6216\u57df\u540d\u3002<\/li>\n<li><strong>\u7aef\u53e3\u865f\uff1a<\/strong>\u6578\u64da\u5eab\u670d\u52d9\u904b\u884c\u7684\u7aef\u53e3\uff0c\u9ed8\u8a8d\u60c5\u6cc1\u4e0b MySQL \u4f7f\u7528 3306\uff0cPostgreSQL \u4f7f\u7528 5432\u3002<\/li>\n<li><strong>\u7528\u6236\u540d\u548c\u5bc6\u78bc\uff1a<\/strong>\u7528\u65bc\u9023\u63a5\u6578\u64da\u5eab\u7684\u6191\u8b49\u3002<\/li>\n<\/ul>\n<h2 id=\"2-%e4%bd%bf%e7%94%a8%e5%91%bd%e4%bb%a4%e8%a1%8c%e5%b7%a5%e5%85%b7%e9%80%b2%e8%a1%8c%e9%80%a3%e6%8e%a5%e6%b8%ac%e8%a9%a6-cmpZwBRXnF\">2. \u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u9032\u884c\u9023\u63a5\u6e2c\u8a66<\/h2>\n<p>\u8a31\u591a\u6578\u64da\u5eab\u7cfb\u7d71\u90fd\u63d0\u4f9b\u4e86\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u4f86\u6e2c\u8a66\u9023\u63a5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u6578\u64da\u5eab\u7684\u9023\u63a5\u6e2c\u8a66\u547d\u4ee4\uff1a<\/p>\n<h3 id=\"mysql-cmpZwBRXnF\">MySQL<\/h3>\n<pre><code>mysql -h \u4e3b\u6a5f\u5730\u5740 -u \u7528\u6236\u540d -p<\/code><\/pre>\n<p>\u57f7\u884c\u4e0a\u8ff0\u547d\u4ee4\u5f8c\uff0c\u7cfb\u7d71\u6703\u63d0\u793a\u60a8\u8f38\u5165\u5bc6\u78bc\u3002\u5982\u679c\u9023\u63a5\u6210\u529f\uff0c\u60a8\u5c07\u9032\u5165 MySQL \u547d\u4ee4\u884c\u754c\u9762\u3002<\/p>\n<h3 id=\"postgresql-cmpZwBRXnF\">PostgreSQL<\/h3>\n<pre><code>psql -h \u4e3b\u6a5f\u5730\u5740 -U \u7528\u6236\u540d -d \u6578\u64da\u5eab\u540d<\/code><\/pre>\n<p>\u540c\u6a23\uff0c\u57f7\u884c\u5f8c\u6703\u8981\u6c42\u8f38\u5165\u5bc6\u78bc\uff0c\u6210\u529f\u5f8c\u5c07\u9032\u5165 PostgreSQL \u547d\u4ee4\u884c\u754c\u9762\u3002<\/p>\n<h3 id=\"mongodb-cmpZwBRXnF\">MongoDB<\/h3>\n<pre><code>mongo \u4e3b\u6a5f\u5730\u5740:\u7aef\u53e3\u865f<\/code><\/pre>\n<p>\u9019\u5c07\u9023\u63a5\u5230\u6307\u5b9a\u7684 MongoDB \u4f3a\u670d\u5668\u3002<\/p>\n<h2 id=\"3-%e4%bd%bf%e7%94%a8%e7%b7%a8%e7%a8%8b%e8%aa%9e%e8%a8%80%e9%80%b2%e8%a1%8c%e9%80%a3%e6%8e%a5%e6%b8%ac%e8%a9%a6-cmpZwBRXnF\">3. \u4f7f\u7528\u7de8\u7a0b\u8a9e\u8a00\u9032\u884c\u9023\u63a5\u6e2c\u8a66<\/h2>\n<p>\u9664\u4e86\u547d\u4ee4\u884c\u5de5\u5177\uff0c\u60a8\u9084\u53ef\u4ee5\u4f7f\u7528\u7de8\u7a0b\u8a9e\u8a00\u4f86\u6e2c\u8a66\u6578\u64da\u5eab\u9023\u63a5\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 PHP \u548c Python \u7684\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"php-cmpZwBRXnF\">PHP<\/h3>\n<pre><code>&lt;?php\n$servername = \"\u4e3b\u6a5f\u5730\u5740\";\n$username = \"\u7528\u6236\u540d\";\n$password = \"\u5bc6\u78bc\";\n$dbname = \"\u6578\u64da\u5eab\u540d\";\n\n\/\/ \u5275\u5efa\u9023\u63a5\n$conn = new mysqli($servername, $username, $password, $dbname);\n\n\/\/ \u6aa2\u67e5\u9023\u63a5\nif ($conn-&gt;connect_error) {\n    die(\"\u9023\u63a5\u5931\u6557: \" . $conn-&gt;connect_error);\n}\necho \"\u9023\u63a5\u6210\u529f\";\n$conn-&gt;close();\n?&gt;<\/code><\/pre>\n<h3 id=\"python-cmpZwBRXnF\">Python<\/h3>\n<pre><code>import mysql.connector\n\ntry:\n    conn = mysql.connector.connect(\n        host=\"\u4e3b\u6a5f\u5730\u5740\",\n        user=\"\u7528\u6236\u540d\",\n        password=\"\u5bc6\u78bc\",\n        database=\"\u6578\u64da\u5eab\u540d\"\n    )\n    print(\"\u9023\u63a5\u6210\u529f\")\nexcept mysql.connector.Error as err:\n    print(\"\u9023\u63a5\u5931\u6557: {}\".format(err))\nfinally:\n    if conn.is_connected():\n        conn.close()<\/code><\/pre>\n<h2 id=\"4-%e6%aa%a2%e6%9f%a5%e9%98%b2%e7%81%ab%e7%89%86%e8%a8%ad%e7%bd%ae-cmpZwBRXnF\">4. \u6aa2\u67e5\u9632\u706b\u7246\u8a2d\u7f6e<\/h2>\n<p>\u5982\u679c\u60a8\u7121\u6cd5\u9023\u63a5\u5230\u6578\u64da\u5eab\uff0c\u8acb\u6aa2\u67e5\u4f3a\u670d\u5668\u7684\u9632\u706b\u7246\u8a2d\u7f6e\u3002\u78ba\u4fdd\u6578\u64da\u5eab\u7684\u7aef\u53e3\u5df2\u7d93\u958b\u653e\uff0c\u4e26\u5141\u8a31\u4f86\u81ea\u60a8\u7684\u4f3a\u670d\u5668\u7684\u9023\u63a5\u8acb\u6c42\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5\u9632\u706b\u7246\u8a2d\u7f6e\uff1a<\/p>\n<pre><code>sudo ufw status<\/code><\/pre>\n<h2 id=\"5-%e6%aa%a2%e6%9f%a5%e6%95%b8%e6%93%9a%e5%ba%ab%e6%9c%8d%e5%8b%99%e7%8b%80%e6%85%8b-cmpZwBRXnF\">5. \u6aa2\u67e5\u6578\u64da\u5eab\u670d\u52d9\u72c0\u614b<\/h2>\n<p>\u78ba\u4fdd\u6578\u64da\u5eab\u670d\u52d9\u6b63\u5728\u904b\u884c\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u6aa2\u67e5 MySQL \u548c PostgreSQL \u7684\u72c0\u614b\uff1a<\/p>\n<h3 id=\"mysql-cmpZwBRXnF\">MySQL<\/h3>\n<pre><code>sudo systemctl status mysql<\/code><\/pre>\n<h3 id=\"postgresql-cmpZwBRXnF\">PostgreSQL<\/h3>\n<pre><code>sudo systemctl status postgresql<\/code><\/pre>\n<h2 id=\"%e7%b8%bd%e7%b5%90-cmpZwBRXnF\">\u7e3d\u7d50<\/h2>\n<p>\u6e2c\u8a66\u4f3a\u670d\u5668\u9023\u63a5\u6578\u64da\u5eab\u7684\u904e\u7a0b\u6d89\u53ca\u591a\u500b\u6b65\u9a5f\uff0c\u5305\u62ec\u78ba\u8a8d\u6578\u64da\u5eab\u4fe1\u606f\u3001\u4f7f\u7528\u547d\u4ee4\u884c\u5de5\u5177\u548c\u7de8\u7a0b\u8a9e\u8a00\u9032\u884c\u6e2c\u8a66\u3001\u6aa2\u67e5\u9632\u706b\u7246\u8a2d\u7f6e\u4ee5\u53ca\u78ba\u4fdd\u6578\u64da\u5eab\u670d\u52d9\u904b\u884c\u3002\u9019\u4e9b\u6b65\u9a5f\u80fd\u5e6b\u52a9\u60a8\u5feb\u901f\u5b9a\u4f4d\u554f\u984c\u4e26\u78ba\u4fdd\u7cfb\u7d71\u7684\u7a69\u5b9a\u904b\u884c\u3002\u5982\u679c\u60a8\u9700\u8981\u9ad8\u6548\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0cServer.HK \u63d0\u4f9b\u591a\u7a2e\u9078\u64c7\uff0c\u6eff\u8db3\u4e0d\u540c\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u6e2c\u8a66\u4f3a\u670d\u5668\u9023\u63a5\u6578\u64da\u5eab\u7684\u6b65\u9a5f\u8207\u65b9\u6cd5\uff0c\u78ba\u4fdd\u6578\u64da\u5eab\u9023\u63a5\u6b63\u5e38\uff0c\u63d0\u5347\u7cfb\u7d71\u7a69\u5b9a\u6027\u8207\u6027\u80fd\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-152401","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152401","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"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=152401"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152401\/revisions"}],"predecessor-version":[{"id":152402,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/152401\/revisions\/152402"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=152401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=152401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=152401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}