{"id":186972,"date":"2024-11-11T10:22:22","date_gmt":"2024-11-11T02:22:22","guid":{"rendered":"https:\/\/server.hk\/cnblog\/186972\/"},"modified":"2024-11-11T10:22:23","modified_gmt":"2024-11-11T02:22:23","slug":"%e6%95%b8%e6%93%9a%e5%ba%ab%e8%bc%95%e9%ac%86%e9%80%a3%e6%8e%a5%e5%af%a6%e7%8f%be%e9%ab%98%e6%95%88%e8%bb%9f%e4%bb%b6%e9%81%8b%e8%a1%8c-%e8%bb%9f%e4%bb%b6%e9%80%a3%e6%8e%a5%e7%9a%84%e6%95%b8%e6%93%9a","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/186972\/","title":{"rendered":"\u6578\u64da\u5eab\u8f15\u9b06\u9023\u63a5\u5be6\u73fe\u9ad8\u6548\u8edf\u4ef6\u904b\u884c (\u8edf\u4ef6\u9023\u63a5\u7684\u6578\u64da\u5eab)"},"content":{"rendered":"<h1 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e8%bc%95%e9%ac%86%e9%80%a3%e6%8e%a5%e5%af%a6%e7%8f%be%e9%ab%98%e6%95%88%e8%bb%9f%e4%bb%b6%e9%81%8b%e8%a1%8c-wSPprEGwUv\">\u6578\u64da\u5eab\u8f15\u9b06\u9023\u63a5\u5be6\u73fe\u9ad8\u6548\u8edf\u4ef6\u904b\u884c<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u6578\u4f4d\u6642\u4ee3\uff0c\u6578\u64da\u5eab\u7684\u4f7f\u7528\u5df2\u6210\u70ba\u8edf\u4ef6\u958b\u767c\u4e2d\u4e0d\u53ef\u6216\u7f3a\u7684\u4e00\u90e8\u5206\u3002\u7121\u8ad6\u662f\u5c0f\u578b\u61c9\u7528\u9084\u662f\u5927\u578b\u4f01\u696d\u7cfb\u7d71\uff0c\u6578\u64da\u5eab\u7684\u9ad8\u6548\u9023\u63a5\u90fd\u80fd\u986f\u8457\u63d0\u5347\u8edf\u4ef6\u7684\u904b\u884c\u6548\u7387\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u8f15\u9b06\u9023\u63a5\u6578\u64da\u5eab\uff0c\u4ee5\u5be6\u73fe\u9ad8\u6548\u7684\u8edf\u4ef6\u904b\u884c\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u793a\u4f8b\u548c\u5efa\u8b70\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-wSPprEGwUv\">\u6578\u64da\u5eab\u9023\u63a5\u7684\u91cd\u8981\u6027<\/h2>\n<p>\u6578\u64da\u5eab\u9023\u63a5\u662f\u6307\u61c9\u7528\u7a0b\u5e8f\u8207\u6578\u64da\u5eab\u4e4b\u9593\u7684\u901a\u4fe1\u904e\u7a0b\u3002\u9019\u4e00\u904e\u7a0b\u7684\u6548\u7387\u76f4\u63a5\u5f71\u97ff\u5230\u6578\u64da\u7684\u8b80\u53d6\u548c\u5beb\u5165\u901f\u5ea6\uff0c\u9032\u800c\u5f71\u97ff\u6574\u9ad4\u61c9\u7528\u7684\u6027\u80fd\u3002\u9ad8\u6548\u7684\u6578\u64da\u5eab\u9023\u63a5\u4e0d\u50c5\u80fd\u63d0\u9ad8\u6578\u64da\u8655\u7406\u7684\u901f\u5ea6\uff0c\u9084\u80fd\u6e1b\u5c11\u7cfb\u7d71\u8cc7\u6e90\u7684\u6d88\u8017\uff0c\u5f9e\u800c\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n<h2 id=\"%e9%81%b8%e6%93%87%e5%90%88%e9%81%a9%e7%9a%84%e6%95%b8%e6%93%9a%e5%ba%ab%e9%a1%9e%e5%9e%8b-wSPprEGwUv\">\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5eab\u985e\u578b<\/h2>\n<p>\u5728\u958b\u59cb\u9023\u63a5\u6578\u64da\u5eab\u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5eab\u985e\u578b\u3002\u5e38\u898b\u7684\u6578\u64da\u5eab\u985e\u578b\u5305\u62ec\u95dc\u4fc2\u578b\u6578\u64da\u5eab\uff08\u5982 MySQL\u3001PostgreSQL\uff09\u548c\u975e\u95dc\u4fc2\u578b\u6578\u64da\u5eab\uff08\u5982 MongoDB\u3001Redis\uff09\u3002\u6bcf\u7a2e\u6578\u64da\u5eab\u90fd\u6709\u5176\u7279\u5b9a\u7684\u512a\u52e2\u548c\u9069\u7528\u5834\u666f\uff1a<\/p>\n<ul>\n<li><strong>\u95dc\u4fc2\u578b\u6578\u64da\u5eab\uff1a<\/strong>\u9069\u5408\u9700\u8981\u8907\u96dc\u67e5\u8a62\u548c\u4e8b\u52d9\u652f\u6301\u7684\u61c9\u7528\u3002<\/li>\n<li><strong>\u975e\u95dc\u4fc2\u578b\u6578\u64da\u5eab\uff1a<\/strong>\u9069\u5408\u9700\u8981\u9ad8\u64f4\u5c55\u6027\u548c\u9748\u6d3b\u6578\u64da\u7d50\u69cb\u7684\u61c9\u7528\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%ad%a5%e9%a9%9f-wSPprEGwUv\">\u6578\u64da\u5eab\u9023\u63a5\u7684\u57fa\u672c\u6b65\u9a5f<\/h2>\n<p>\u9023\u63a5\u6578\u64da\u5eab\u7684\u57fa\u672c\u6b65\u9a5f\u901a\u5e38\u5305\u62ec\u4ee5\u4e0b\u5e7e\u500b\u65b9\u9762\uff1a<\/p>\n<ol>\n<li><strong>\u5b89\u88dd\u6578\u64da\u5eab\u9a45\u52d5\uff1a<\/strong>\u6839\u64da\u6240\u9078\u64c7\u7684\u6578\u64da\u5eab\u985e\u578b\uff0c\u5b89\u88dd\u76f8\u61c9\u7684\u9a45\u52d5\u7a0b\u5e8f\u3002\u4f8b\u5982\uff0c\u5c0d\u65bc MySQL\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd\u9a45\u52d5\uff1a<\/li>\n<pre><code>pip install mysql-connector-python<\/code><\/pre>\n<li><strong>\u5efa\u7acb\u9023\u63a5\uff1a<\/strong>\u4f7f\u7528\u9a45\u52d5\u7a0b\u5e8f\u63d0\u4f9b\u7684 API \u5efa\u7acb\u8207\u6578\u64da\u5eab\u7684\u9023\u63a5\u3002\u4ee5\u4e0b\u662f Python \u4e2d\u9023\u63a5 MySQL \u7684\u793a\u4f8b\uff1a<\/li>\n<pre><code>import mysql.connector\n\nconnection = mysql.connector.connect(\n    host=\"localhost\",\n    user=\"yourusername\",\n    password=\"yourpassword\",\n    database=\"yourdatabase\"\n)<\/code><\/pre>\n<li><strong>\u57f7\u884c\u67e5\u8a62\uff1a<\/strong>\u4e00\u65e6\u5efa\u7acb\u9023\u63a5\uff0c\u5c31\u53ef\u4ee5\u57f7\u884c SQL \u67e5\u8a62\u4f86\u8b80\u53d6\u6216\u5beb\u5165\u6578\u64da\u3002\u4f8b\u5982\uff1a<\/li>\n<pre><code>cursor = connection.cursor()\ncursor.execute(\"SELECT * FROM yourtable\")\nresults = cursor.fetchall()\nfor row in results:\n    print(row)<\/code><\/pre>\n<li><strong>\u95dc\u9589\u9023\u63a5\uff1a<\/strong>\u5728\u5b8c\u6210\u64cd\u4f5c\u5f8c\uff0c\u52d9\u5fc5\u95dc\u9589\u6578\u64da\u5eab\u9023\u63a5\u4ee5\u91cb\u653e\u8cc7\u6e90\uff1a<\/li>\n<pre><code>connection.close()<\/code><\/pre>\n<\/ol>\n<h2 id=\"%e6%9c%80%e4%bd%b3%e5%af%a6%e8%b8%90-wSPprEGwUv\">\u6700\u4f73\u5be6\u8e10<\/h2>\n<p>\u70ba\u4e86\u78ba\u4fdd\u6578\u64da\u5eab\u9023\u63a5\u7684\u9ad8\u6548\u6027\uff0c\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6700\u4f73\u5be6\u8e10\uff1a<\/p>\n<ul>\n<li><strong>\u4f7f\u7528\u9023\u63a5\u6c60\uff1a<\/strong>\u9023\u63a5\u6c60\u53ef\u4ee5\u91cd\u7528\u73fe\u6709\u7684\u6578\u64da\u5eab\u9023\u63a5\uff0c\u6e1b\u5c11\u5efa\u7acb\u65b0\u9023\u63a5\u7684\u958b\u92b7\u3002<\/li>\n<li><strong>\u512a\u5316\u67e5\u8a62\uff1a<\/strong>\u78ba\u4fdd SQL \u67e5\u8a62\u7d93\u904e\u512a\u5316\uff0c\u4ee5\u63d0\u9ad8\u57f7\u884c\u6548\u7387\u3002<\/li>\n<li><strong>\u5b9a\u671f\u76e3\u63a7\uff1a<\/strong>\u5b9a\u671f\u76e3\u63a7\u6578\u64da\u5eab\u6027\u80fd\uff0c\u53ca\u6642\u767c\u73fe\u4e26\u89e3\u6c7a\u6f5b\u5728\u554f\u984c\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-wSPprEGwUv\">\u7d50\u8ad6<\/h2>\n<p>\u6578\u64da\u5eab\u7684\u9ad8\u6548\u9023\u63a5\u5c0d\u65bc\u8edf\u4ef6\u7684\u904b\u884c\u81f3\u95dc\u91cd\u8981\u3002\u901a\u904e\u9078\u64c7\u5408\u9069\u7684\u6578\u64da\u5eab\u985e\u578b\u3001\u9075\u5faa\u57fa\u672c\u7684\u9023\u63a5\u6b65\u9a5f\u4ee5\u53ca\u5be6\u65bd\u6700\u4f73\u5be6\u8e10\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u986f\u8457\u63d0\u5347\u61c9\u7528\u7684\u6027\u80fd\u548c\u7528\u6236\u9ad4\u9a57\u3002\u7121\u8ad6\u662f\u4f7f\u7528 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u9084\u662f\u5176\u4ed6\u670d\u52d9\uff0c\u78ba\u4fdd\u6578\u64da\u5eab\u9023\u63a5\u7684\u9ad8\u6548\u6027\u90fd\u662f\u6210\u529f\u7684\u95dc\u9375\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8f15\u9b06\u9023\u63a5\u6578\u64da\u5eab\uff0c\u5be6\u73fe\u9ad8\u6548\u8edf\u4ef6\u904b\u884c\uff0c\u63d0\u5347\u6027\u80fd\u8207\u7a69\u5b9a\u6027\uff0c\u52a9\u60a8\u5feb\u901f\u958b\u767c\u8207\u90e8\u7f72\u61c9\u7528\u7a0b\u5f0f\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-186972","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/186972","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=186972"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/186972\/revisions"}],"predecessor-version":[{"id":186973,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/186972\/revisions\/186973"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=186972"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=186972"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=186972"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}