{"id":25457,"date":"2024-11-24T14:11:09","date_gmt":"2024-11-24T06:11:09","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25457\/"},"modified":"2024-11-24T14:11:09","modified_gmt":"2024-11-24T06:11:09","slug":"%e5%a6%82%e4%bd%95%e4%bc%98%e9%9b%85%e5%9c%b0%e4%b8%ba-python-%e5%ae%a2%e6%88%b7%e7%ab%af%e7%9a%84-sql-%e6%9f%a5%e8%af%a2%e8%ae%be%e7%bd%ae%e8%b6%85%e6%97%b6%e6%97%b6%e9%97%b4%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25457\/","title":{"rendered":"\u5982\u4f55\u4f18\u96c5\u5730\u4e3a Python \u5ba2\u6237\u7aef\u7684 SQL \u67e5\u8be2\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173061576458261.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f18\u96c5\u5730\u4e3a Python \u5ba2\u6237\u7aef\u7684 SQL \u67e5\u8be2\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f18\u96c5\u5730\u4e3a Python \u5ba2\u6237\u7aef\u7684 SQL \u67e5\u8be2\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u4f18\u96c5\u5730\u5bf9  \u5ba2\u6237\u7aef\u7684 sql \u67e5\u8be2\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4\uff1f<\/strong><\/p>\n<p>\u5f53\u4f7f\u7528 django orm\u3001peewee\u3001sqlalchemy \u7b49 orm\uff0c\u4ee5\u53ca py \u7b49\u9a71\u52a8\u5e93\u3001fastapi\u3001flask\u3001django \u7b49 app\uff0c\u4ee5\u53ca uvicorn\u3001gunicorn \u7b49\u670d\u52a1\u5668\u65f6\uff0c\u6709\u65f6\u9700\u8981\u5728\u8d85\u8fc7\u4e00\u5b9a\u9608\u503c\u540e\u7ec8\u6b62 sql \u67e5\u8be2\uff0c\u4ee5\u9632\u6b62\u5b89\u5168\u9690\u60a3\u3002<\/p>\n<p><strong>\u5b9e\u73b0\u65b9\u6cd5<\/strong><\/p>\n<p>\u4e3a\u4e86\u4f18\u96c5\u5730\u5b9e\u73b0\u6b64\u76ee\u7684\uff0c\u53ef\u4ee5\u4f7f\u7528 pymysql \u5e93\u7684\u53c2\u6570\uff1a<\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<ul>\n<li> <strong>connection_timeout:<\/strong> \u6570\u636e\u5e93\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09<\/li>\n<li> <strong>read_timeout:<\/strong> \u6570\u636e\u5e93\u8bfb\u64cd\u4f5c\u8d85\u65f6\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09<\/li>\n<li> <strong>write_timeout:<\/strong> \u6570\u636e\u5e93\u5199\u64cd\u4f5c\u8d85\u65f6\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 pymysql \u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u4ee5\u4e0b\u53c2\u6570\u6765\u9650\u5236 sql \u67e5\u8be2\u65f6\u95f4\uff1a<\/p>\n<pre>import pymysql\n\n# \u6253\u5f00\u6570\u636e\u5e93\u8fde\u63a5\nconnection = pymysql.connect(\n    host=\"localhost\",\n    user=\"root\",\n    password=\"password\",\n    database=\"database_name\",\n    connection_timeout=60,\n    read_timeout=60,\n    write_timeout=60,\n)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u901a\u8fc7\u5c06 <strong>read_timeout<\/strong> \u8bbe\u7f6e\u4e3a 60 \u79d2\uff0c\u4efb\u4f55\u8d85\u8fc7 60 \u79d2\u7684 sql \u67e5\u8be2\u90fd\u4f1a\u8d85\u65f6\u5e76\u7ec8\u6b62\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f18\u96c5\u5730\u4e3a Python \u5ba2\u6237\u7aef\u7684 SQL \u67e5\u8be2\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4\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>\u5982\u4f55\u4f18\u96c5\u5730\u5bf9 \u5ba2\u6237\u7aef\u7684 sql \u67e5\u8be2\u8bbe\u7f6e\u8d85\u65f6\u65f6\u95f4\uff1f \u5f53\u4f7f\u7528 django orm\u3001peewee\u3001sqlalchemy \u7b49 orm\uff0c\u4ee5\u53ca py \u7b49\u9a71\u52a8\u5e93\u3001fastapi\u3001flask\u3001django \u7b49 app\uff0c\u4ee5\u53ca uvicorn\u3001gunicorn \u7b49\u670d\u52a1\u5668\u65f6\uff0c\u6709\u65f6\u9700\u8981\u5728\u8d85\u8fc7\u4e00\u5b9a\u9608\u503c\u540e\u7ec8\u6b62 sql \u67e5\u8be2\uff0c\u4ee5\u9632\u6b62\u5b89\u5168\u9690\u60a3\u3002 \u5b9e\u73b0\u65b9\u6cd5 \u4e3a\u4e86\u4f18\u96c5\u5730\u5b9e\u73b0\u6b64\u76ee\u7684\uff0c\u53ef\u4ee5\u4f7f\u7528 pymysql \u5e93\u7684\u53c2\u6570\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b connection_timeout: \u6570\u636e\u5e93\u8fde\u63a5\u8d85\u65f6\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09 read_timeout: \u6570\u636e\u5e93\u8bfb\u64cd\u4f5c\u8d85\u65f6\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09 write_timeout: \u6570\u636e\u5e93\u5199\u64cd\u4f5c\u8d85\u65f6\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09 \u793a\u4f8b \u5728\u4f7f\u7528 pymysql \u65f6\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e\u4ee5\u4e0b\u53c2\u6570\u6765\u9650\u5236 sql \u67e5\u8be2\u65f6\u95f4\uff1a import pymysql # \u6253\u5f00\u6570\u636e\u5e93\u8fde\u63a5 connection = pymysql.connect( host=&#8221;localhost&#8221;, user=&#8221;root&#8221;, password=&#8221;password&#8221;, database=&#8221;database_name&#8221;, connection_timeout=60, read_timeout=60, write_timeout=60, ) \u767b\u5f55\u540e\u590d\u5236 \u901a\u8fc7\u5c06 read_timeout \u8bbe\u7f6e\u4e3a 60 \u79d2\uff0c\u4efb\u4f55\u8d85\u8fc7 [&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-25457","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25457","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=25457"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25457\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25457"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25457"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25457"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}