{"id":171277,"date":"2024-11-07T01:24:18","date_gmt":"2024-11-06T17:24:18","guid":{"rendered":"https:\/\/server.hk\/cnblog\/171277\/"},"modified":"2024-11-07T01:24:19","modified_gmt":"2024-11-06T17:24:19","slug":"%e5%89%8d%e7%ab%af%e8%bc%95%e9%ac%86%e5%af%a6%e7%8f%be%e9%80%a3%e6%8e%a5mysql%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%8c%e7%b0%a1%e5%96%ae%e5%bf%ab%e6%8d%b7%e5%8f%88%e9%ab%98%e6%95%88%ef%bc%81-%e5%89%8d","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/171277\/","title":{"rendered":"\u524d\u7aef\u8f15\u9b06\u5be6\u73fe\u9023\u63a5MySQL\u6578\u64da\u5eab\uff0c\u7c21\u55ae\u5feb\u6377\u53c8\u9ad8\u6548\uff01 (\u524d\u7aef\u9023\u63a5mysql\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"%e5%89%8d%e7%ab%af%e8%bc%95%e9%ac%86%e5%af%a6%e7%8f%be%e9%80%a3%e6%8e%a5mysql%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%8c%e7%b0%a1%e5%96%ae%e5%bf%ab%e6%8d%b7%e5%8f%88%e9%ab%98%e6%95%88%ef%bc%81-FgdtDIrKXY\">\u524d\u7aef\u8f15\u9b06\u5be6\u73fe\u9023\u63a5MySQL\u6578\u64da\u5eab\uff0c\u7c21\u55ae\u5feb\u6377\u53c8\u9ad8\u6548\uff01<\/h1>\n<p>\u5728\u73fe\u4eca\u7684\u7db2\u9801\u958b\u767c\u4e2d\uff0c\u524d\u7aef\u8207\u5f8c\u7aef\u7684\u9023\u63a5\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002\u5c24\u5176\u662f\u7576\u6211\u5011\u9700\u8981\u5f9e\u6578\u64da\u5eab\u4e2d\u7372\u53d6\u6216\u5b58\u5132\u6578\u64da\u6642\uff0c\u5982\u4f55\u6709\u6548\u5730\u9023\u63a5MySQL\u6578\u64da\u5eab\u6210\u70ba\u4e86\u958b\u767c\u8005\u5fc5\u9808\u638c\u63e1\u7684\u6280\u80fd\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728\u524d\u7aef\u8f15\u9b06\u5be6\u73fe\u8207MySQL\u6578\u64da\u5eab\u7684\u9023\u63a5\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u7c21\u55ae\u7684\u793a\u4f8b\u548c\u4ee3\u78bc\u7247\u6bb5\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u5feb\u901f\u4e0a\u624b\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%81%b8%e6%93%87mysql%ef%bc%9f-FgdtDIrKXY\">\u70ba\u4ec0\u9ebc\u9078\u64c7MySQL\uff1f<\/h2>\n<p>MySQL\u662f\u4e00\u7a2e\u6d41\u884c\u7684\u958b\u6e90\u95dc\u4fc2\u578b\u6578\u64da\u5eab\u7ba1\u7406\u7cfb\u7d71\uff0c\u56e0\u5176\u7a69\u5b9a\u6027\u548c\u9ad8\u6548\u6027\u800c\u53d7\u5230\u5ee3\u6cdb\u4f7f\u7528\u3002\u5b83\u652f\u6301\u591a\u7a2e\u64cd\u4f5c\u7cfb\u7d71\uff0c\u4e26\u4e14\u64c1\u6709\u5f37\u5927\u7684\u793e\u5340\u652f\u6301\u3002\u5c0d\u65bc\u9700\u8981\u8655\u7406\u5927\u91cf\u6578\u64da\u7684\u61c9\u7528\u7a0b\u5e8f\u4f86\u8aaa\uff0cMySQL\u63d0\u4f9b\u4e86\u826f\u597d\u7684\u6027\u80fd\u548c\u53ef\u64f4\u5c55\u6027\u3002<\/p>\n<h2 id=\"%e5%89%8d%e7%ab%af%e5%a6%82%e4%bd%95%e9%80%a3%e6%8e%a5mysql%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-FgdtDIrKXY\">\u524d\u7aef\u5982\u4f55\u9023\u63a5MySQL\u6578\u64da\u5eab\uff1f<\/h2>\n<p>\u76f4\u63a5\u5728\u524d\u7aef\u9023\u63a5MySQL\u6578\u64da\u5eab\u4e26\u4e0d\u662f\u4e00\u500b\u63a8\u85a6\u7684\u505a\u6cd5\uff0c\u56e0\u70ba\u9019\u6a23\u6703\u66b4\u9732\u6578\u64da\u5eab\u7684\u654f\u611f\u4fe1\u606f\uff0c\u4e26\u4e14\u53ef\u80fd\u6703\u5c0e\u81f4\u5b89\u5168\u554f\u984c\u3002\u901a\u5e38\u7684\u505a\u6cd5\u662f\u901a\u904e\u5f8c\u7aefAPI\u4f86\u9032\u884c\u6578\u64da\u7684\u4ea4\u4e92\u3002\u4ee5\u4e0b\u662f\u5be6\u73fe\u9019\u4e00\u904e\u7a0b\u7684\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e8%a8%ad%e7%bd%ae%e5%be%8c%e7%ab%afapi-FgdtDIrKXY\">1. \u8a2d\u7f6e\u5f8c\u7aefAPI<\/h3>\n<p>\u9996\u5148\uff0c\u6211\u5011\u9700\u8981\u4e00\u500b\u5f8c\u7aef\u670d\u52d9\u4f86\u8655\u7406\u524d\u7aef\u7684\u8acb\u6c42\u3002\u9019\u88e1\u4ee5Node.js\u548cExpress\u70ba\u4f8b\uff0c\u4f86\u8a2d\u7f6e\u4e00\u500b\u7c21\u55ae\u7684API\u3002<\/p>\n<pre><code>const express = require('express');\nconst mysql = require('mysql');\nconst app = express();\nconst port = 3000;\n\n\/\/ \u5275\u5efaMySQL\u9023\u63a5\nconst connection = mysql.createConnection({\n  host: 'localhost',\n  user: 'your_username',\n  password: 'your_password',\n  database: 'your_database'\n});\n\n\/\/ \u9023\u63a5\u5230\u6578\u64da\u5eab\nconnection.connect((err) =&gt; {\n  if (err) throw err;\n  console.log('Connected to MySQL Database!');\n});\n\n\/\/ \u7372\u53d6\u6578\u64da\u7684API\napp.get('\/api\/data', (req, res) =&gt; {\n  connection.query('SELECT * FROM your_table', (err, results) =&gt; {\n    if (err) throw err;\n    res.json(results);\n  });\n});\n\n\/\/ \u555f\u52d5\u670d\u52d9\napp.listen(port, () =&gt; {\n  console.log(`Server running at http:\/\/localhost:${port}`);\n});<\/code><\/pre>\n<h3 id=\"2-%e5%9c%a8%e5%89%8d%e7%ab%af%e7%99%bc%e9%80%81%e8%ab%8b%e6%b1%82-FgdtDIrKXY\">2. \u5728\u524d\u7aef\u767c\u9001\u8acb\u6c42<\/h3>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u53ef\u4ee5\u5728\u524d\u7aef\u4f7f\u7528JavaScript\u7684fetch API\u4f86\u8acb\u6c42\u5f8c\u7aefAPI\uff0c\u7372\u53d6\u6578\u64da\u3002<\/p>\n<pre><code>fetch('http:\/\/localhost:3000\/api\/data')\n  .then(response =&gt; response.json())\n  .then(data =&gt; {\n    console.log(data);\n    \/\/ \u5728\u9019\u88e1\u8655\u7406\u7372\u53d6\u5230\u7684\u6578\u64da\n  })\n  .catch(error =&gt; console.error('Error:', error));<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e5%85%a8%e6%80%a7%e8%80%83%e9%87%8f-FgdtDIrKXY\">\u5b89\u5168\u6027\u8003\u91cf<\/h2>\n<p>\u5728\u5be6\u969b\u61c9\u7528\u4e2d\uff0c\u5b89\u5168\u6027\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5efa\u8b70\u4f86\u63d0\u9ad8\u5b89\u5168\u6027\uff1a<\/p>\n<ul>\n<li>\u4f7f\u7528\u74b0\u5883\u8b8a\u91cf\u4f86\u5b58\u5132\u6578\u64da\u5eab\u7684\u9023\u63a5\u4fe1\u606f\u3002<\/li>\n<li>\u5c0dAPI\u8acb\u6c42\u9032\u884c\u8eab\u4efd\u9a57\u8b49\u548c\u6388\u6b0a\u3002<\/li>\n<li>\u4f7f\u7528\u53c3\u6578\u5316\u67e5\u8a62\u4f86\u9632\u6b62SQL\u6ce8\u5165\u653b\u64ca\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-FgdtDIrKXY\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4ee5\u4e0a\u6b65\u9a5f\uff0c\u6211\u5011\u53ef\u4ee5\u8f15\u9b06\u5730\u5728\u524d\u7aef\u5be6\u73fe\u8207MySQL\u6578\u64da\u5eab\u7684\u9023\u63a5\u3002\u96d6\u7136\u76f4\u63a5\u5728\u524d\u7aef\u9023\u63a5\u6578\u64da\u5eab\u4e26\u4e0d\u5b89\u5168\uff0c\u4f46\u901a\u904e\u8a2d\u7f6e\u5f8c\u7aefAPI\uff0c\u6211\u5011\u53ef\u4ee5\u6709\u6548\u5730\u9032\u884c\u6578\u64da\u4ea4\u4e92\u3002\u9019\u7a2e\u65b9\u6cd5\u4e0d\u50c5\u7c21\u55ae\u5feb\u6377\uff0c\u9084\u80fd\u78ba\u4fdd\u6578\u64da\u7684\u5b89\u5168\u6027\u3002<\/p>\n<p>\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u7a69\u5b9a\u7684 <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\u4f86\u90e8\u7f72\u60a8\u7684\u61c9\u7528\u7a0b\u5e8f\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\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u985e\u578b\u7684 <a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a>\uff0c\u6211\u5011\u90fd\u80fd\u70ba\u60a8\u63d0\u4f9b\u9ad8\u6548\u7684\u670d\u52d9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f15\u9b06\u5be6\u73fe\u524d\u7aef\u9023\u63a5MySQL\u6578\u64da\u5eab\uff0c\u7c21\u55ae\u5feb\u6377\uff0c\u63d0\u5347\u958b\u767c\u6548\u7387\uff0c\u8b93\u6578\u64da\u4ea4\u4e92\u66f4\u6d41\u66a2\uff01<\/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-171277","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/171277","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=171277"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/171277\/revisions"}],"predecessor-version":[{"id":171278,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/171277\/revisions\/171278"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=171277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=171277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=171277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}