{"id":180408,"date":"2024-11-09T10:01:22","date_gmt":"2024-11-09T02:01:22","guid":{"rendered":"https:\/\/server.hk\/cnblog\/180408\/"},"modified":"2024-11-09T10:01:22","modified_gmt":"2024-11-09T02:01:22","slug":"%e6%b7%b1%e5%ba%a6%e8%a7%a3%e5%af%86%ef%bc%9a%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e7%9a%84%e9%87%8d%e8%a6%81%e6%80%a7%e5%8f%8a%e8%a9%b3%e7%b4%b0%e6%93%8d%e4%bd%9c-%e6%95%b8%e6%93%9a%e5%ba%ab","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/180408\/","title":{"rendered":"\u6df1\u5ea6\u89e3\u5bc6\uff1a\u6578\u64da\u5eab\u9023\u63a5\u7684\u91cd\u8981\u6027\u53ca\u8a73\u7d30\u64cd\u4f5c (\u6578\u64da\u5eab \u9023\u63a5 \u8a73\u89e3)"},"content":{"rendered":"<h1 id=\"%e6%b7%b1%e5%ba%a6%e8%a7%a3%e5%af%86%ef%bc%9a%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e7%9a%84%e9%87%8d%e8%a6%81%e6%80%a7%e5%8f%8a%e8%a9%b3%e7%b4%b0%e6%93%8d%e4%bd%9c-%e6%95%b8%e6%93%9a%e5%ba%ab-ZwmSNMgonx\">\u6df1\u5ea6\u89e3\u5bc6\uff1a\u6578\u64da\u5eab\u9023\u63a5\u7684\u91cd\u8981\u6027\u53ca\u8a73\u7d30\u64cd\u4f5c (\u6578\u64da\u5eab \u9023\u63a5 \u8a73\u89e3)<\/h1>\n<p>\u5728\u7576\u4eca\u6578\u64da\u9a45\u52d5\u7684\u4e16\u754c\u4e2d\uff0c\u6578\u64da\u5eab\u9023\u63a5\u7684\u7a69\u5b9a\u6027\u548c\u6548\u7387\u5c0d\u65bc\u61c9\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u81f3\u95dc\u91cd\u8981\u3002\u7121\u8ad6\u662f\u4f01\u696d\u7d1a\u61c9\u7528\u9084\u662f\u500b\u4eba\u9805\u76ee\uff0c\u6578\u64da\u5eab\u7684\u9023\u63a5\u90fd\u626e\u6f14\u8457\u95dc\u9375\u89d2\u8272\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u6578\u64da\u5eab\u9023\u63a5\u7684\u91cd\u8981\u6027\u53ca\u5176\u8a73\u7d30\u64cd\u4f5c\uff0c\u5e6b\u52a9\u8b80\u8005\u66f4\u597d\u5730\u7406\u89e3\u9019\u4e00\u4e3b\u984c\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e7%9a%84%e9%87%8d%e8%a6%81%e6%80%a7-ZwmSNMgonx\">\u6578\u64da\u5eab\u9023\u63a5\u7684\u91cd\u8981\u6027<\/h2>\n<p>\u6578\u64da\u5eab\u9023\u63a5\u662f\u61c9\u7528\u7a0b\u5e8f\u8207\u6578\u64da\u5eab\u4e4b\u9593\u7684\u6a4b\u6a11\u3002\u5b83\u4f7f\u5f97\u61c9\u7528\u7a0b\u5e8f\u80fd\u5920\u8b80\u53d6\u3001\u5beb\u5165\u548c\u7ba1\u7406\u6578\u64da\u3002\u4ee5\u4e0b\u662f\u6578\u64da\u5eab\u9023\u63a5\u7684\u91cd\u8981\u6027\uff1a<\/p>\n<ul>\n<li><strong>\u6578\u64da\u5b58\u53d6\u6548\u7387\uff1a<\/strong>\u826f\u597d\u7684\u6578\u64da\u5eab\u9023\u63a5\u53ef\u4ee5\u986f\u8457\u63d0\u9ad8\u6578\u64da\u5b58\u53d6\u7684\u901f\u5ea6\uff0c\u5f9e\u800c\u63d0\u5347\u6574\u9ad4\u61c9\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u3002<\/li>\n<li><strong>\u8cc7\u6e90\u7ba1\u7406\uff1a<\/strong>\u901a\u904e\u6709\u6548\u7684\u9023\u63a5\u7ba1\u7406\uff0c\u53ef\u4ee5\u6e1b\u5c11\u8cc7\u6e90\u7684\u6d6a\u8cbb\uff0c\u78ba\u4fdd\u7cfb\u7d71\u7684\u7a69\u5b9a\u6027\u3002<\/li>\n<li><strong>\u5b89\u5168\u6027\uff1a<\/strong>\u6578\u64da\u5eab\u9023\u63a5\u7684\u5b89\u5168\u6027\u76f4\u63a5\u5f71\u97ff\u5230\u6578\u64da\u7684\u4fdd\u8b77\uff0c\u6b63\u78ba\u7684\u9023\u63a5\u914d\u7f6e\u53ef\u4ee5\u9632\u6b62\u672a\u7d93\u6388\u6b0a\u7684\u8a2a\u554f\u3002<\/li>\n<li><strong>\u53ef\u64f4\u5c55\u6027\uff1a<\/strong>\u96a8\u8457\u696d\u52d9\u7684\u589e\u9577\uff0c\u6578\u64da\u5eab\u9023\u63a5\u7684\u53ef\u64f4\u5c55\u6027\u5c07\u5f71\u97ff\u5230\u7cfb\u7d71\u7684\u672a\u4f86\u767c\u5c55\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%93%8d%e4%bd%9c-ZwmSNMgonx\">\u6578\u64da\u5eab\u9023\u63a5\u7684\u57fa\u672c\u64cd\u4f5c<\/h2>\n<p>\u5728\u9032\u884c\u6578\u64da\u5eab\u9023\u63a5\u6642\uff0c\u901a\u5e38\u9700\u8981\u9075\u5faa\u4ee5\u4e0b\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e9%81%b8%e6%93%87%e6%95%b8%e6%93%9a%e5%ba%ab%e9%a1%9e%e5%9e%8b-ZwmSNMgonx\">1. \u9078\u64c7\u6578\u64da\u5eab\u985e\u578b<\/h3>\n<p>\u9996\u5148\uff0c\u6839\u64da\u61c9\u7528\u9700\u6c42\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5eab\u985e\u578b\uff0c\u5982\u95dc\u4fc2\u578b\u6578\u64da\u5eab\uff08\u5982 MySQL\u3001PostgreSQL\uff09\u6216\u975e\u95dc\u4fc2\u578b\u6578\u64da\u5eab\uff08\u5982 MongoDB\uff09\u3002<\/p>\n<h3 id=\"2-%e5%ae%89%e8%a3%9d%e6%95%b8%e6%93%9a%e5%ba%ab%e9%a9%85%e5%8b%95-ZwmSNMgonx\">2. \u5b89\u88dd\u6578\u64da\u5eab\u9a45\u52d5<\/h3>\n<p>\u6839\u64da\u6240\u9078\u64c7\u7684\u6578\u64da\u5eab\u985e\u578b\uff0c\u5b89\u88dd\u76f8\u61c9\u7684\u6578\u64da\u5eab\u9a45\u52d5\u3002\u4f8b\u5982\uff0c\u5c0d\u65bc MySQL\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd\u9a45\u52d5\uff1a<\/p>\n<pre><code>npm install mysql<\/code><\/pre>\n<h3 id=\"3-%e5%bb%ba%e7%ab%8b%e6%95%b8%e6%93%9a%e5%ba%ab%e9%80%a3%e6%8e%a5-ZwmSNMgonx\">3. \u5efa\u7acb\u6578\u64da\u5eab\u9023\u63a5<\/h3>\n<p>\u4f7f\u7528\u7de8\u7a0b\u8a9e\u8a00\uff08\u5982 JavaScript\u3001Python\u3001PHP \u7b49\uff09\u4f86\u5efa\u7acb\u6578\u64da\u5eab\u9023\u63a5\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528 Node.js \u9023\u63a5 MySQL \u7684\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>const mysql = require('mysql');\nconst connection = mysql.createConnection({\n    host: 'localhost',\n    user: 'yourUsername',\n    password: 'yourPassword',\n    database: 'yourDatabase'\n});\n\nconnection.connect((err) =&gt; {\n    if (err) {\n        console.error('Error connecting: ' + err.stack);\n        return;\n    }\n    console.log('Connected as id ' + connection.threadId);\n});<\/code><\/pre>\n<h3 id=\"4-%e5%9f%b7%e8%a1%8c%e6%9f%a5%e8%a9%a2-ZwmSNMgonx\">4. \u57f7\u884c\u67e5\u8a62<\/h3>\n<p>\u4e00\u65e6\u9023\u63a5\u6210\u529f\uff0c\u5c31\u53ef\u4ee5\u57f7\u884c SQL \u67e5\u8a62\u4f86\u8b80\u53d6\u6216\u5beb\u5165\u6578\u64da\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>connection.query('SELECT * FROM yourTable', (error, results, fields) =&gt; {\n    if (error) throw error;\n    console.log(results);\n});<\/code><\/pre>\n<h3 id=\"5-%e9%97%9c%e9%96%89%e9%80%a3%e6%8e%a5-ZwmSNMgonx\">5. \u95dc\u9589\u9023\u63a5<\/h3>\n<p>\u5728\u5b8c\u6210\u6578\u64da\u64cd\u4f5c\u5f8c\uff0c\u61c9\u8a72\u95dc\u9589\u6578\u64da\u5eab\u9023\u63a5\u4ee5\u91cb\u653e\u8cc7\u6e90\uff1a<\/p>\n<pre><code>connection.end();<\/code><\/pre>\n<h2 id=\"%e6%9c%80%e4%bd%b3%e5%af%a6%e8%b8%90-ZwmSNMgonx\">\u6700\u4f73\u5be6\u8e10<\/h2>\n<p>\u5728\u9032\u884c\u6578\u64da\u5eab\u9023\u63a5\u6642\uff0c\u9075\u5faa\u4e00\u4e9b\u6700\u4f73\u5be6\u8e10\u53ef\u4ee5\u63d0\u9ad8\u7cfb\u7d71\u7684\u7a69\u5b9a\u6027\u548c\u5b89\u5168\u6027\uff1a<\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u9023\u63a5\u6c60\uff1a<\/strong>\u9023\u63a5\u6c60\u53ef\u4ee5\u91cd\u7528\u73fe\u6709\u7684\u9023\u63a5\uff0c\u6e1b\u5c11\u9023\u63a5\u5efa\u7acb\u7684\u958b\u92b7\u3002<\/li>\n<li><strong>\u52a0\u5bc6\u9023\u63a5\uff1a<\/strong>\u4f7f\u7528 SSL\/TLS \u52a0\u5bc6\u6578\u64da\u5eab\u9023\u63a5\uff0c\u4ee5\u4fdd\u8b77\u6578\u64da\u7684\u5b89\u5168\u6027\u3002<\/li>\n<li><strong>\u5b9a\u671f\u76e3\u63a7\uff1a<\/strong>\u5b9a\u671f\u76e3\u63a7\u6578\u64da\u5eab\u7684\u6027\u80fd\u548c\u9023\u63a5\u72c0\u614b\uff0c\u53ca\u6642\u767c\u73fe\u4e26\u89e3\u6c7a\u554f\u984c\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-ZwmSNMgonx\">\u7e3d\u7d50<\/h2>\n<p>\u6578\u64da\u5eab\u9023\u63a5\u5728\u73fe\u4ee3\u61c9\u7528\u7a0b\u5e8f\u4e2d\u626e\u6f14\u8457\u4e0d\u53ef\u6216\u7f3a\u7684\u89d2\u8272\u3002\u901a\u904e\u6b63\u78ba\u7684\u64cd\u4f5c\u548c\u6700\u4f73\u5be6\u8e10\uff0c\u53ef\u4ee5\u78ba\u4fdd\u6578\u64da\u5eab\u7684\u9ad8\u6548\u3001\u5b89\u5168\u904b\u884c\u3002\u5c0d\u65bc\u9700\u8981\u7a69\u5b9a\u548c\u9ad8\u6548\u6578\u64da\u5eab\u9023\u63a5\u7684\u7528\u6236\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u5c07\u662f\u660e\u667a\u4e4b\u8209\u3002\u7121\u8ad6\u662f <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u985e\u578b\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a>\uff0c\u90fd\u80fd\u70ba\u60a8\u7684\u6578\u64da\u5eab\u63d0\u4f9b\u7a69\u5b9a\u7684\u652f\u6301\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6df1\u5165\u63a2\u8a0e\u6578\u64da\u5eab\u9023\u63a5\u7684\u91cd\u8981\u6027\u53ca\u5176\u8a73\u7d30\u64cd\u4f5c\uff0c\u5e6b\u52a9\u60a8\u638c\u63e1\u6578\u64da\u5eab\u7ba1\u7406\u7684\u95dc\u9375\u6280\u5de7\u8207\u6700\u4f73\u5be6\u8e10\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-180408","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/180408","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=180408"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/180408\/revisions"}],"predecessor-version":[{"id":180409,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/180408\/revisions\/180409"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=180408"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=180408"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=180408"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}