{"id":200930,"date":"2025-05-06T14:39:44","date_gmt":"2025-05-06T06:39:44","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200930\/"},"modified":"2025-05-06T14:39:44","modified_gmt":"2025-05-06T06:39:44","slug":"%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3-mysql-%e6%9f%a5%e8%af%a2%e4%b8%ad%e5%87%ba%e7%8e%b0%e7%9a%84-%e9%94%99%e8%af%af%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200930\/","title":{"rendered":"\u5982\u4f55\u89e3\u51b3 MySQL \u67e5\u8be2\u4e2d\u51fa\u73b0\u7684 \u201c\u201d \u9519\u8bef\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u89e3\u51b3 MySQL \u67e5\u8be2\u4e2d\u51fa\u73b0\u7684 \u201c\u201d \u9519\u8bef\uff1f<\/h1>\n<p>\u4ece\u73b0\u5728\u5f00\u59cb\uff0c\u52aa\u529b\u5b66\u4e60\u5427\uff01\u672c\u6587\u4e3b\u8981\u8bb2\u89e3\u4e86\u7b49\u7b49\u76f8\u5173\u77e5\u8bc6\u70b9\uff0c\u6211\u4f1a\u5728\u4e3b\u673a\u5b9d\u8d1d\u4e2d\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u7684\u7cfb\u5217\u6587\u7ae0\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u5e76\u79ef\u6781\u7559\u8a00\u5efa\u8bae\u3002\u4e0b\u9762\u5c31\u5148\u4e00\u8d77\u6765\u770b\u4e00\u4e0b\u672c\u7bc7\u6b63\u6587\u5185\u5bb9\u5427\uff0c\u5e0c\u671b\u80fd\u5e2e\u5230\u4f60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241121\/1732193159673f2b8763eea.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u89e3\u51b3\u201c<\/strong><\/p>\n<hr>\n<p><strong>\u201d\u9519\u8bef\u7684 mysql \u67e5\u8be2<\/strong> <\/p>\n<p>\u5728\u6267\u884c mysql \u67e5\u8be2\u65f6\u9047\u5230\u201c<\/p>\n<hr>\n<p>\u201d\u9519\u8bef\uff0c\u8be5\u9519\u8bef\u63d0\u793a\u60a8\u9047\u5230\u8bed\u6cd5\u6216\u8bed\u4e49\u95ee\u9898\u3002\u4ee5\u4e0b\u662f\u5bfc\u81f4\u6b64\u9519\u8bef\u7684\u5e38\u89c1\u539f\u56e0\u4ee5\u53ca\u5982\u4f55\u89e3\u51b3\u5b83\uff1a <\/p>\n<p><strong>\u539f\u56e0 1\uff1a\u672a\u6b63\u786e\u8f6c\u4e49\u7279\u6b8a\u5b57\u7b26<\/strong><\/p>\n<p>\u7279\u6b8a\u5b57\u7b26\uff0c\u5982\u5f15\u53f7 (&#8220;)\u3001\u53cd\u659c\u6760 ()\u3001\u5355\u5f15\u53f7 (&#8216;) \u548c\u6362\u884c\u7b26\uff0c\u9700\u8981\u4f7f\u7528\u53cd\u659c\u6760 () \u8fdb\u884c\u8f6c\u4e49\u3002\u672a\u8f6c\u4e49\u8fd9\u4e9b\u5b57\u7b26\u4f1a\u5bfc\u81f4\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong>\u4f7f\u7528\u53cd\u659c\u6760\u8f6c\u4e49\u6240\u6709\u7279\u6b8a\u5b57\u7b26\u3002<\/p>\n<p><strong>\u539f\u56e0 2\uff1a\u672a\u6b63\u786e\u5730\u6307\u5b9a\u5217\u540d<\/strong><\/p>\n<p>\u5217\u540d\u5fc5\u987b\u7528\u53cd\u5f15\u53f7 (`) \u62ec\u8d77\u6765\u3002\u672a\u7528\u53cd\u5f15\u53f7\u62ec\u8d77\u5217\u540d\u4f1a\u5bfc\u81f4\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong>\u7528\u53cd\u5f15\u53f7\u62ec\u8d77\u6240\u6709\u5217\u540d\u3002<\/p>\n<p><strong>\u539f\u56e0 3\uff1a\u67e5\u8be2\u8bed\u6cd5\u4e0d\u6b63\u786e<\/strong><\/p>\n<p>mysql \u67e5\u8be2\u5fc5\u987b\u9075\u5faa\u7279\u5b9a\u7684\u8bed\u6cd5\u89c4\u5219\u3002\u4e0d\u6b63\u786e\u7684\u8bed\u6cd5\u4f1a\u5bfc\u81f4\u8bed\u6cd5\u9519\u8bef\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong>\u4ed4\u7ec6\u68c0\u67e5\u67e5\u8be2\u8bed\u6cd5\uff0c\u786e\u4fdd\u5b83\u7b26\u5408 mysql \u8bed\u6cd5\u89c4\u8303\u3002<\/p>\n<p>\u4ee5\u4e0b\u4ee3\u7801\u793a\u4f8b\u6f14\u793a\u4e86\u5982\u4f55\u66f4\u6b63\u4e0a\u9762\u9519\u8bef\u4e2d\u7684\u95ee\u9898\uff1a<\/p>\n<pre>import mysql.connector\n\n# \u8fde\u63a5\u5230\u6570\u636e\u5e93\nconn = mysql.connector.connect(\n    host=\"\u4e3b\u673a\u540d\u6216IP\u5730\u5740\",\n    user=\"\u6570\u636e\u5e93\u7528\u6237\u540d\",\n    password=\"\u6570\u636e\u5e93\u5bc6\u7801\",\n    database=\"\u6570\u636e\u5e93\u540d\"\n)\n\n# \u521b\u5efa\u4e00\u4e2a\u6e38\u6807\u5bf9\u8c61\nmycursor = conn.cursor()\n\n# \u5b9a\u4e49\u67e5\u8be2\u5b57\u7b26\u4e32\nquery_str = \"SELECT `yu`, `rt` FROM `tablename`\"\n\ntry:\n    mycursor.execute(query_str)\n    results = mycursor.fetchall()\n    for row in results:\n        yu, rt = row\n        print(f\"yu: {yu}, rt: {rt}\")\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\nfinally:\n    # \u5173\u95ed\u6e38\u6807\u548c\u8fde\u63a5\n    mycursor.close()\n    conn.close()<\/pre>\n<p>\u4eca\u5929\u5173\u4e8e\u300a\u5982\u4f55\u89e3\u51b3 MySQL \u67e5\u8be2\u4e2d\u51fa\u73b0\u7684 \u201c\u201d \u9519\u8bef\uff1f\u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u89e3\u51b3 MySQL \u67e5\u8be2\u4e2d\u51fa\u73b0&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200930","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200930","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=200930"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200930\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200930"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200930"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200930"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}