{"id":25509,"date":"2024-11-24T15:32:43","date_gmt":"2024-11-24T07:32:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25509\/"},"modified":"2024-11-24T15:32:43","modified_gmt":"2024-11-24T07:32:43","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-python-%e5%ae%a2%e6%88%b7%e7%ab%af%e8%ae%be%e7%bd%ae-sql-%e6%9f%a5%e8%af%a2%e8%b6%85%e6%97%b6%e6%9c%ba%e5%88%b6%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25509\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 Python \u5ba2\u6237\u7aef\u8bbe\u7f6e SQL \u67e5\u8be2\u8d85\u65f6\u673a\u5236\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173062485632117.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 Python \u5ba2\u6237\u7aef\u8bbe\u7f6e SQL \u67e5\u8be2\u8d85\u65f6\u673a\u5236\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 Python \u5ba2\u6237\u7aef\u8bbe\u7f6e SQL \u67e5\u8be2\u8d85\u65f6\u673a\u5236\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u5ba2\u6237\u7aef sql \u67e5\u8be2\u8d85\u65f6\u673a\u5236<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 orm \u6846\u67b6\uff08\u4f8b\u5982 django orm\u3001peewee \u6216 sqlalchemy\uff09\u3001\u9a71\u52a8\u5e93\uff08\u4f8b\u5982 py\uff09\u3001web \u6846\u67b6\uff08\u4f8b\u5982 fastapi\u3001flask \u6216 django\uff09\uff0c\u4ee5\u53ca\u670d\u52a1\u5668\uff08\u4f8b\u5982 uvicorn \u6216 gunicorn\uff09\u65f6\uff0c\u5982\u4f55\u5b9e\u73b0 sql \u67e5\u8be2\u8d85\u65f6\u7ec8\u6b62\uff1f<\/p>\n<p>\u4f8b\u5982\uff0c\u4f7f\u7528 uvicorn\u3001fastapi\u3001peewee \u548c pymysql \u65f6\uff0c\u67d0\u4e9b sql \u67e5\u8be2\u53ef\u80fd\u9700\u8981\u5f88\u957f\u65f6\u95f4\u624d\u80fd\u5b8c\u6210\u3002\u4f46\u662f\uff0c\u8fd9\u6837\u505a\u5b58\u5728\u6f5c\u5728\u7684\u5b89\u5168\u98ce\u9669\u3002\u6211\u4eec\u9700\u8981\u8bbe\u7f6e\u4e00\u4e2a\u67e5\u8be2\u65f6\u95f4\u4e0a\u9650\uff0c\u4ee5\u9632\u6b62\u5355\u4e2a sql \u67e5\u8be2\u7684\u8fd0\u884c\u65f6\u95f4\u8d85\u8fc7\u9884\u671f\u503c\u3002<\/p>\n<p>\u4ee5\u4e0b\u662f\u5b9e\u73b0\u6b64\u76ee\u7684\u7684\u4f18\u96c5\u89e3\u51b3\u65b9\u6848\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>pymysql<\/strong><\/p>\n<p>pymysql \u63d0\u4f9b\u4e86\u4ee5\u4e0b\u53c2\u6570\u6765\u8bbe\u7f6e\u8d85\u65f6\uff1a<\/p>\n<ul>\n<li>&#8220;connection_timeout&#8221;: \u6307\u5b9a\u4e0e\u6570\u636e\u5e93\u5efa\u7acb\u8fde\u63a5\u7684\u8d85\u65f6\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\u3002<\/li>\n<li>&#8220;read_timeout&#8221;: \u6307\u5b9a\u4ece\u6570\u636e\u5e93\u8bfb\u53d6\u6570\u636e\u65f6\u4f7f\u7528\u7684\u8d85\u65f6\u65f6\u95f4\u3002<\/li>\n<li>&#8220;write_timeout&#8221;: \u6307\u5b9a\u5411\u6570\u636e\u5e93\u5199\u5165\u6570\u636e\u65f6\u4f7f\u7528\u7684\u8d85\u65f6\u65f6\u95f4\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u5c06\u8bbe\u7f6e\u6240\u6709\u8d85\u65f6\u65f6\u95f4\u4e3a 60 \u79d2\uff1a<\/p>\n<pre>import pymysql\n\nconnection = pymysql.connect(\n    connection_timeout=60,\n    read_timeout=60,\n    write_timeout=60,\n)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 Python \u5ba2\u6237\u7aef\u8bbe\u7f6e SQL \u67e5\u8be2\u8d85\u65f6\u673a\u5236\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5ba2\u6237\u7aef sql \u67e5\u8be2\u8d85\u65f6\u673a\u5236 \u5728\u4f7f\u7528 orm \u6846\u67b6\uff08\u4f8b\u5982 django orm\u3001peewee \u6216 sqlalchemy\uff09\u3001\u9a71\u52a8\u5e93\uff08\u4f8b\u5982 py\uff09\u3001web \u6846\u67b6\uff08\u4f8b\u5982 fastapi\u3001flask \u6216 django\uff09\uff0c\u4ee5\u53ca\u670d\u52a1\u5668\uff08\u4f8b\u5982 uvicorn \u6216 gunicorn\uff09\u65f6\uff0c\u5982\u4f55\u5b9e\u73b0 sql \u67e5\u8be2\u8d85\u65f6\u7ec8\u6b62\uff1f \u4f8b\u5982\uff0c\u4f7f\u7528 uvicorn\u3001fastapi\u3001peewee \u548c pymysql \u65f6\uff0c\u67d0\u4e9b sql \u67e5\u8be2\u53ef\u80fd\u9700\u8981\u5f88\u957f\u65f6\u95f4\u624d\u80fd\u5b8c\u6210\u3002\u4f46\u662f\uff0c\u8fd9\u6837\u505a\u5b58\u5728\u6f5c\u5728\u7684\u5b89\u5168\u98ce\u9669\u3002\u6211\u4eec\u9700\u8981\u8bbe\u7f6e\u4e00\u4e2a\u67e5\u8be2\u65f6\u95f4\u4e0a\u9650\uff0c\u4ee5\u9632\u6b62\u5355\u4e2a sql \u67e5\u8be2\u7684\u8fd0\u884c\u65f6\u95f4\u8d85\u8fc7\u9884\u671f\u503c\u3002 \u4ee5\u4e0b\u662f\u5b9e\u73b0\u6b64\u76ee\u7684\u7684\u4f18\u96c5\u89e3\u51b3\u65b9\u6848\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b pymysql pymysql \u63d0\u4f9b\u4e86\u4ee5\u4e0b\u53c2\u6570\u6765\u8bbe\u7f6e\u8d85\u65f6\uff1a &#8220;connection_timeout&#8221;: \u6307\u5b9a\u4e0e\u6570\u636e\u5e93\u5efa\u7acb\u8fde\u63a5\u7684\u8d85\u65f6\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\u3002 &#8220;read_timeout&#8221;: \u6307\u5b9a\u4ece\u6570\u636e\u5e93\u8bfb\u53d6\u6570\u636e\u65f6\u4f7f\u7528\u7684\u8d85\u65f6\u65f6\u95f4\u3002 &#8220;write_timeout&#8221;: \u6307\u5b9a\u5411\u6570\u636e\u5e93\u5199\u5165\u6570\u636e\u65f6\u4f7f\u7528\u7684\u8d85\u65f6\u65f6\u95f4\u3002 \u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u5c06\u8bbe\u7f6e\u6240\u6709\u8d85\u65f6\u65f6\u95f4\u4e3a 60 \u79d2\uff1a import pymysql connection = pymysql.connect( connection_timeout=60, read_timeout=60, write_timeout=60, ) \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 Python [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-25509","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25509","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=25509"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25509\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25509"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25509"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25509"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}