{"id":200767,"date":"2025-05-06T12:35:10","date_gmt":"2025-05-06T04:35:10","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200767\/"},"modified":"2025-05-06T12:35:10","modified_gmt":"2025-05-06T04:35:10","slug":"%e5%a6%82%e4%bd%95%e8%ae%be%e7%bd%ae-python-%e4%b8%ad%e7%9a%84-sql-%e6%9f%a5%e8%af%a2%e8%b6%85%e6%97%b6%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200767\/","title":{"rendered":"\u5982\u4f55\u8bbe\u7f6e Python \u4e2d\u7684 SQL \u67e5\u8be2\u8d85\u65f6\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>\u5982\u4f55\u8bbe\u7f6e Python \u4e2d\u7684 SQL \u67e5\u8be2\u8d85\u65f6\uff1f<\/h1>\n<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241114\/1731555567673570ef6386d.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5728 python \u5ba2\u6237\u7aef\u5b9e\u73b0 sql \u67e5\u8be2\u8d85\u65f6<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 python \u8fdb\u884c sql \u67e5\u8be2\u65f6\uff0c\u6709\u65f6\u9700\u8981\u9650\u5236\u67e5\u8be2\u6267\u884c\u65f6\u95f4\u4ee5\u9632\u6b62\u5b89\u5168\u9690\u60a3\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728\u4f7f\u7528 django orm\u3001peewee\u3001sqlalchemy \u7b49 orm \u6846\u67b6\uff1bpymysql \u7b49\u9a71\u52a8\u7a0b\u5e8f\u5e93\uff1b\u4ee5\u53ca fastapi\u3001flask\u3001django \u7b49\u5e94\u7528\u7a0b\u5e8f\u6846\u67b6\uff1b\u4ee5\u53ca uwsgi\u3001gunicorn \u7b49\u670d\u52a1\u5668\u65f6\u8bbe\u7f6e sql \u67e5\u8be2\u8d85\u65f6\u3002<\/p>\n<p>\u5bf9\u4e8e\u4f7f\u7528 uwsgi + fastapi + peewee + pymysql \u7b49\u7ec4\u5408\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e pymysql \u8fde\u63a5\u8d85\u65f6\u53c2\u6570\u6765\u5b9e\u73b0 sql \u67e5\u8be2\u8d85\u65f6\uff1a<\/p>\n<pre>pymysql.connect(\n    host=\"localhost\",\n    user=\"user\",\n    password=\"password\",\n    db=\"database\",\n    connection_timeout=60,  # \u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\uff08\u79d2\uff09\n    read_timeout=60,  # \u8bfb\u8d85\u65f6\u65f6\u95f4\uff08\u79d2\uff09\n    write_timeout=60,  # \u5199\u8d85\u65f6\u65f6\u95f4\uff08\u79d2\uff09\n)<\/pre>\n<p>\u901a\u8fc7\u8bbe\u7f6e\u8fd9\u4e9b\u53c2\u6570\uff0c\u53ef\u4ee5\u9650\u5236 sql \u67e5\u8be2\u7684\u6267\u884c\u65f6\u95f4\u3002\u5f53\u67e5\u8be2\u8d85\u8fc7\u6307\u5b9a\u7684\u8d85\u65f6\u65f6\u95f4\u65f6\uff0c\u5c06\u629b\u51fa\u8d85\u65f6\u5f02\u5e38\uff0c\u7ec8\u6b62\u67e5\u8be2\u3002<\/p>\n<p>\u7ec8\u4e8e\u4ecb\u7ecd\u5b8c\u5566\uff01\u5c0f\u4f19\u4f34\u4eec\uff0c\u8fd9\u7bc7\u5173\u4e8e\u300a\u5982\u4f55\u8bbe\u7f6e Python \u4e2d\u7684 SQL \u67e5\u8be2\u8d85\u65f6\uff1f\u300b\u7684\u4ecb\u7ecd\u5e94\u8be5\u8ba9\u4f60\u6536\u83b7\u591a\u591a\u4e86\u5427\uff01\u6b22\u8fce\u5927\u5bb6\u6536\u85cf\u6216\u5206\u4eab\u7ed9\u66f4\u591a\u9700\u8981\u5b66\u4e60\u7684\u670b\u53cb\u5427~\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\u4e5f\u4f1a\u53d1\u5e03\u6570\u636e\u5e93\u76f8\u5173\u77e5\u8bc6\uff0c\u5feb\u6765\u5173\u6ce8\u5427\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u8bbe\u7f6e Python \u4e2d\u7684 S&#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-200767","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200767","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=200767"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200767\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200767"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200767"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200767"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}