{"id":1117517,"date":"2025-01-08T18:26:43","date_gmt":"2025-01-08T10:26:43","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1117517.html"},"modified":"2025-01-08T18:26:46","modified_gmt":"2025-01-08T10:26:46","slug":"%e5%a6%82%e4%bd%95%e7%94%a8python%e5%a4%84%e7%90%86n%e4%b8%aa%e6%95%b0%e6%8d%ae%e5%ba%93","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1117517.html","title":{"rendered":"\u5982\u4f55\u7528python\u5904\u7406n\u4e2a\u6570\u636e\u5e93"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25081411\/056978b7-b11e-4b00-b0d4-d7211d167f58.webp\" alt=\"\u5982\u4f55\u7528python\u5904\u7406n\u4e2a\u6570\u636e\u5e93\" \/><\/p>\n<p><p> <strong>\u5982\u4f55\u7528Python\u5904\u7406n\u4e2a\u6570\u636e\u5e93<\/strong><\/p>\n<\/p>\n<p><p>\u8981\u7528Python\u5904\u7406\u591a\u4e2a\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u3001\u5229\u7528ORM\u5de5\u5177\u3001\u7f16\u5199\u81ea\u5b9a\u4e49\u7684\u6570\u636e\u5e93\u7ba1\u7406\u811a\u672c\u3002\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63a2\u8ba8\u8fd9\u51e0\u79cd\u65b9\u6cd5\uff0c\u5e76\u63d0\u4f9b\u793a\u4f8b\u4ee3\u7801\u4ee5\u4f9b\u53c2\u8003\u3002<strong>\u4f7f\u7528\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u3001\u5229\u7528ORM\u5de5\u5177\u3001\u7f16\u5199\u81ea\u5b9a\u4e49\u7684\u6570\u636e\u5e93\u7ba1\u7406\u811a\u672c<\/strong>\uff0c\u5176\u4e2d\uff0c\u6211\u4eec\u5c06\u8be6\u7ec6\u63cf\u8ff0\u5982\u4f55\u5229\u7528ORM\u5de5\u5177\u8fdb\u884c\u6570\u636e\u5e93\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<hr>\n<p><h2>\u4e00\u3001\u4f7f\u7528\u6570\u636e\u5e93\u8fde\u63a5\u6c60<\/h2>\n<\/p>\n<p><p>\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u662f\u4e00\u79cd\u7528\u4e8e\u7ba1\u7406\u6570\u636e\u5e93\u8fde\u63a5\u7684\u6280\u672f\u3002\u5b83\u53ef\u4ee5\u6709\u6548\u5730\u51cf\u5c11\u8fde\u63a5\u548c\u65ad\u5f00\u6570\u636e\u5e93\u7684\u5f00\u9500\uff0c\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u53ef\u9760\u6027\u3002\u5e38\u89c1\u7684\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u5e93\u5305\u62ec<code>SQLAlchemy<\/code>\u548c<code>DBUtils<\/code>\u3002<\/p>\n<\/p>\n<p><h3>1\u3001SQLAlchemy\u8fde\u63a5\u6c60<\/h3>\n<\/p>\n<p><p><code>SQLAlchemy<\/code>\u662fPython\u4e2d\u4e00\u4e2a\u6d41\u884c\u7684SQL\u5de5\u5177\u5305\u548cORM\u5e93\u3002\u5b83\u63d0\u4f9b\u4e86\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684\u8fde\u63a5\u6c60\uff0c\u53ef\u4ee5\u8f7b\u677e\u7ba1\u7406\u591a\u4e2a\u6570\u636e\u5e93\u8fde\u63a5\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sqlalchemy import create_engine<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e\u5e93\u5f15\u64ce<\/strong><\/h2>\n<p>engine1 = create_engine(&#39;mysql+pymysql:\/\/user:password@host1\/dbname1&#39;)<\/p>\n<p>engine2 = create_engine(&#39;mysql+pymysql:\/\/user:password@host2\/dbname2&#39;)<\/p>\n<h2><strong>\u6267\u884c\u6570\u636e\u5e93\u64cd\u4f5c<\/strong><\/h2>\n<p>with engine1.connect() as connection1:<\/p>\n<p>    result1 = connection1.execute(&quot;SELECT * FROM table1&quot;)<\/p>\n<p>    for row in result1:<\/p>\n<p>        print(row)<\/p>\n<p>with engine2.connect() as connection2:<\/p>\n<p>    result2 = connection2.execute(&quot;SELECT * FROM table2&quot;)<\/p>\n<p>    for row in result2:<\/p>\n<p>        print(row)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001DBUtils\u8fde\u63a5\u6c60<\/h3>\n<\/p>\n<p><p><code>DBUtils<\/code>\u662f\u53e6\u4e00\u4e2a\u6d41\u884c\u7684\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u5e93\uff0c\u5b83\u652f\u6301\u591a\u79cd\u6570\u636e\u5e93\u7c7b\u578b\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528<code>DBUtils<\/code>\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from DBUtils.PooledDB import PooledDB<\/p>\n<p>import pymysql<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e\u5e93\u8fde\u63a5\u6c60<\/strong><\/h2>\n<p>pool1 = PooledDB(pymysql, 5, host=&#39;host1&#39;, user=&#39;user&#39;, passwd=&#39;password&#39;, db=&#39;dbname1&#39;)<\/p>\n<p>pool2 = PooledDB(pymysql, 5, host=&#39;host2&#39;, user=&#39;user&#39;, passwd=&#39;password&#39;, db=&#39;dbname2&#39;)<\/p>\n<h2><strong>\u83b7\u53d6\u8fde\u63a5\u5e76\u6267\u884c\u6570\u636e\u5e93\u64cd\u4f5c<\/strong><\/h2>\n<p>connection1 = pool1.connection()<\/p>\n<p>cursor1 = connection1.cursor()<\/p>\n<p>cursor1.execute(&quot;SELECT * FROM table1&quot;)<\/p>\n<p>for row in cursor1.fetchall():<\/p>\n<p>    print(row)<\/p>\n<p>connection1.close()<\/p>\n<p>connection2 = pool2.connection()<\/p>\n<p>cursor2 = connection2.cursor()<\/p>\n<p>cursor2.execute(&quot;SELECT * FROM table2&quot;)<\/p>\n<p>for row in cursor2.fetchall():<\/p>\n<p>    print(row)<\/p>\n<p>connection2.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e8c\u3001\u5229\u7528ORM\u5de5\u5177<\/h2>\n<\/p>\n<p><p>ORM\uff08\u5bf9\u8c61\u5173\u7cfb\u6620\u5c04\uff09\u5de5\u5177\u53ef\u4ee5\u5c06\u6570\u636e\u5e93\u8868\u6620\u5c04\u4e3aPython\u7c7b\uff0c\u4f7f\u5f97\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u9762\u5411\u5bf9\u8c61\u7684\u65b9\u5f0f\u64cd\u4f5c\u6570\u636e\u5e93\u3002\u5e38\u7528\u7684ORM\u5de5\u5177\u6709<code>SQLAlchemy<\/code>\u548c<code>Django ORM<\/code>\u3002<\/p>\n<\/p>\n<p><h3>1\u3001SQLAlchemy ORM<\/h3>\n<\/p>\n<p><p><code>SQLAlchemy<\/code>\u4e0d\u4ec5\u662f\u4e00\u4e2a\u8fde\u63a5\u6c60\u5e93\uff0c\u8fd8\u662f\u4e00\u4e2a\u529f\u80fd\u5f3a\u5927\u7684ORM\u5de5\u5177\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528<code>SQLAlchemy ORM<\/code>\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sqlalchemy import create_engine, Column, Integer, String<\/p>\n<p>from sqlalchemy.ext.declarative import declarative_base<\/p>\n<p>from sqlalchemy.orm import sessionmaker<\/p>\n<p>Base = declarative_base()<\/p>\n<h2><strong>\u5b9a\u4e49\u6620\u5c04\u7c7b<\/strong><\/h2>\n<p>class Table1(Base):<\/p>\n<p>    __tablename__ = &#39;table1&#39;<\/p>\n<p>    id = Column(Integer, primary_key=True)<\/p>\n<p>    name = Column(String)<\/p>\n<p>class Table2(Base):<\/p>\n<p>    __tablename__ = &#39;table2&#39;<\/p>\n<p>    id = Column(Integer, primary_key=True)<\/p>\n<p>    name = Column(String)<\/p>\n<h2><strong>\u521b\u5efa\u6570\u636e\u5e93\u5f15\u64ce<\/strong><\/h2>\n<p>engine1 = create_engine(&#39;mysql+pymysql:\/\/user:password@host1\/dbname1&#39;)<\/p>\n<p>engine2 = create_engine(&#39;mysql+pymysql:\/\/user:password@host2\/dbname2&#39;)<\/p>\n<h2><strong>\u521b\u5efa\u4f1a\u8bdd<\/strong><\/h2>\n<p>Session1 = sessionmaker(bind=engine1)<\/p>\n<p>session1 = Session1()<\/p>\n<p>Session2 = sessionmaker(bind=engine2)<\/p>\n<p>session2 = Session2()<\/p>\n<h2><strong>\u67e5\u8be2\u6570\u636e<\/strong><\/h2>\n<p>results1 = session1.query(Table1).all()<\/p>\n<p>for row in results1:<\/p>\n<p>    print(row.name)<\/p>\n<p>results2 = session2.query(Table2).all()<\/p>\n<p>for row in results2:<\/p>\n<p>    print(row.name)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001Django ORM<\/h3>\n<\/p>\n<p><p><code>Django ORM<\/code>\u662f<code>Django<\/code>\u6846\u67b6\u81ea\u5e26\u7684ORM\u5de5\u5177\u3002\u5982\u679c\u4f60\u6b63\u5728\u4f7f\u7528<code>Django<\/code>\u5f00\u53d1\u4e00\u4e2aWeb\u5e94\u7528\uff0c\u53ef\u4ee5\u4f7f\u7528<code>Django ORM<\/code>\u6765\u7ba1\u7406\u591a\u4e2a\u6570\u636e\u5e93\u3002<\/p>\n<\/p>\n<p><p>\u5728<code>Django<\/code>\u7684<code>settings.py<\/code>\u6587\u4ef6\u4e2d\u914d\u7f6e\u591a\u4e2a\u6570\u636e\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">DATABASES = {<\/p>\n<p>    &#39;default&#39;: {<\/p>\n<p>        &#39;ENGINE&#39;: &#39;django.db.backends.mysql&#39;,<\/p>\n<p>        &#39;NAME&#39;: &#39;dbname1&#39;,<\/p>\n<p>        &#39;USER&#39;: &#39;user&#39;,<\/p>\n<p>        &#39;PASSWORD&#39;: &#39;password&#39;,<\/p>\n<p>        &#39;HOST&#39;: &#39;host1&#39;,<\/p>\n<p>        &#39;PORT&#39;: &#39;3306&#39;,<\/p>\n<p>    },<\/p>\n<p>    &#39;db2&#39;: {<\/p>\n<p>        &#39;ENGINE&#39;: &#39;django.db.backends.mysql&#39;,<\/p>\n<p>        &#39;NAME&#39;: &#39;dbname2&#39;,<\/p>\n<p>        &#39;USER&#39;: &#39;user&#39;,<\/p>\n<p>        &#39;PASSWORD&#39;: &#39;password&#39;,<\/p>\n<p>        &#39;HOST&#39;: &#39;host2&#39;,<\/p>\n<p>        &#39;PORT&#39;: &#39;3306&#39;,<\/p>\n<p>    },<\/p>\n<p>}<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u6a21\u578b\u4e2d\u4f7f\u7528\u4e0d\u540c\u7684\u6570\u636e\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from django.db import models<\/p>\n<p>class Table1(models.Model):<\/p>\n<p>    name = models.CharField(max_length=100)<\/p>\n<p>    class Meta:<\/p>\n<p>        db_table = &#39;table1&#39;<\/p>\n<p>        app_label = &#39;default&#39;<\/p>\n<p>class Table2(models.Model):<\/p>\n<p>    name = models.CharField(max_length=100)<\/p>\n<p>    class Meta:<\/p>\n<p>        db_table = &#39;table2&#39;<\/p>\n<p>        app_label = &#39;db2&#39;<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u67e5\u8be2\u6570\u636e\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from myapp.models import Table1, Table2<\/p>\n<p>results1 = Table1.objects.using(&#39;default&#39;).all()<\/p>\n<p>for row in results1:<\/p>\n<p>    print(row.name)<\/p>\n<p>results2 = Table2.objects.using(&#39;db2&#39;).all()<\/p>\n<p>for row in results2:<\/p>\n<p>    print(row.name)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e09\u3001\u7f16\u5199\u81ea\u5b9a\u4e49\u7684\u6570\u636e\u5e93\u7ba1\u7406\u811a\u672c<\/h2>\n<\/p>\n<p><p>\u5982\u679c\u4f60\u4e0d\u60f3\u4f7f\u7528\u7b2c\u4e09\u65b9\u5e93\uff0c\u53ef\u4ee5\u7f16\u5199\u81ea\u5b9a\u4e49\u7684\u6570\u636e\u5e93\u7ba1\u7406\u811a\u672c\u6765\u5904\u7406\u591a\u4e2a\u6570\u636e\u5e93\u3002\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5\u7075\u6d3b\u5730\u6ee1\u8db3\u4f60\u7684\u9700\u6c42\uff0c\u4f46\u9700\u8981\u66f4\u591a\u7684\u5de5\u4f5c\u91cf\u3002<\/p>\n<\/p>\n<p><h3>1\u3001\u4f7f\u7528PyMySQL\u8fde\u63a5MySQL\u6570\u636e\u5e93<\/h3>\n<\/p>\n<p><p><code>PyMySQL<\/code>\u662f\u4e00\u4e2a\u7eafPython\u5b9e\u73b0\u7684MySQL\u5ba2\u6237\u7aef\u5e93\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528<code>PyMySQL<\/code>\u8fde\u63a5\u591a\u4e2a\u6570\u636e\u5e93\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pymysql<\/p>\n<h2><strong>\u8fde\u63a5\u5230\u7b2c\u4e00\u4e2a\u6570\u636e\u5e93<\/strong><\/h2>\n<p>connection1 = pymysql.connect(host=&#39;host1&#39;, user=&#39;user&#39;, password=&#39;password&#39;, db=&#39;dbname1&#39;)<\/p>\n<p>cursor1 = connection1.cursor()<\/p>\n<p>cursor1.execute(&quot;SELECT * FROM table1&quot;)<\/p>\n<p>for row in cursor1.fetchall():<\/p>\n<p>    print(row)<\/p>\n<p>connection1.close()<\/p>\n<h2><strong>\u8fde\u63a5\u5230\u7b2c\u4e8c\u4e2a\u6570\u636e\u5e93<\/strong><\/h2>\n<p>connection2 = pymysql.connect(host=&#39;host2&#39;, user=&#39;user&#39;, password=&#39;password&#39;, db=&#39;dbname2&#39;)<\/p>\n<p>cursor2 = connection2.cursor()<\/p>\n<p>cursor2.execute(&quot;SELECT * FROM table2&quot;)<\/p>\n<p>for row in cursor2.fetchall():<\/p>\n<p>    print(row)<\/p>\n<p>connection2.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2\u3001\u4f7f\u7528psycopg2\u8fde\u63a5PostgreSQL\u6570\u636e\u5e93<\/h3>\n<\/p>\n<p><p><code>psycopg2<\/code>\u662f\u4e00\u4e2a\u7528\u4e8e\u8fde\u63a5PostgreSQL\u6570\u636e\u5e93\u7684Python\u5e93\u3002\u4e0b\u9762\u662f\u4e00\u4e2a\u4f7f\u7528<code>psycopg2<\/code>\u8fde\u63a5\u591a\u4e2a\u6570\u636e\u5e93\u7684\u793a\u4f8b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import psycopg2<\/p>\n<h2><strong>\u8fde\u63a5\u5230\u7b2c\u4e00\u4e2a\u6570\u636e\u5e93<\/strong><\/h2>\n<p>connection1 = psycopg2.connect(host=&#39;host1&#39;, user=&#39;user&#39;, password=&#39;password&#39;, dbname=&#39;dbname1&#39;)<\/p>\n<p>cursor1 = connection1.cursor()<\/p>\n<p>cursor1.execute(&quot;SELECT * FROM table1&quot;)<\/p>\n<p>for row in cursor1.fetchall():<\/p>\n<p>    print(row)<\/p>\n<p>connection1.close()<\/p>\n<h2><strong>\u8fde\u63a5\u5230\u7b2c\u4e8c\u4e2a\u6570\u636e\u5e93<\/strong><\/h2>\n<p>connection2 = psycopg2.connect(host=&#39;host2&#39;, user=&#39;user&#39;, password=&#39;password&#39;, dbname=&#39;dbname2&#39;)<\/p>\n<p>cursor2 = connection2.cursor()<\/p>\n<p>cursor2.execute(&quot;SELECT * FROM table2&quot;)<\/p>\n<p>for row in cursor2.fetchall():<\/p>\n<p>    print(row)<\/p>\n<p>connection2.close()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u56db\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u5728\u8fd9\u7bc7\u6587\u7ae0\u4e2d\uff0c\u6211\u4eec\u63a2\u8ba8\u4e86\u5982\u4f55\u7528Python\u5904\u7406\u591a\u4e2a\u6570\u636e\u5e93\u3002\u6211\u4eec\u4ecb\u7ecd\u4e86\u4f7f\u7528\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u3001\u5229\u7528ORM\u5de5\u5177\u3001\u7f16\u5199\u81ea\u5b9a\u4e49\u7684\u6570\u636e\u5e93\u7ba1\u7406\u811a\u672c\u7b49\u65b9\u6cd5\u3002\u4f7f\u7528\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u53ef\u4ee5\u63d0\u9ad8\u5e94\u7528\u7a0b\u5e8f\u7684\u6027\u80fd\u548c\u53ef\u9760\u6027\uff0c\u5229\u7528ORM\u5de5\u5177\u53ef\u4ee5\u65b9\u4fbf\u5730\u8fdb\u884c\u9762\u5411\u5bf9\u8c61\u7684\u6570\u636e\u5e93\u64cd\u4f5c\uff0c\u800c\u7f16\u5199\u81ea\u5b9a\u4e49\u7684\u6570\u636e\u5e93\u7ba1\u7406\u811a\u672c\u5219\u53ef\u4ee5\u7075\u6d3b\u5730\u6ee1\u8db3\u7279\u5b9a\u9700\u6c42\u3002\u5e0c\u671b\u8fd9\u7bc7\u6587\u7ae0\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff0c\u80fd\u591f\u8ba9\u4f60\u66f4\u597d\u5730\u5904\u7406\u591a\u4e2a\u6570\u636e\u5e93\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u9009\u62e9\u5408\u9002\u7684Python\u5e93\u6765\u5904\u7406\u591a\u4e2a\u6570\u636e\u5e93\uff1f<\/strong><br \/>\u5728\u5904\u7406\u591a\u4e2a\u6570\u636e\u5e93\u65f6\uff0c\u9009\u62e9\u5408\u9002\u7684Python\u5e93\u975e\u5e38\u5173\u952e\u3002\u5e38\u7528\u7684\u5e93\u5305\u62ecSQLAlchemy\u3001Pandas\u548cDjango ORM\u7b49\u3002SQLAlchemy\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u636e\u5e93\u62bd\u8c61\u548c\u64cd\u4f5c\u529f\u80fd\uff0c\u9002\u5408\u590d\u6742\u7684\u5e94\u7528\u573a\u666f\uff1bPandas\u5219\u5728\u6570\u636e\u5206\u6790\u65b9\u9762\u8868\u73b0\u4f18\u5f02\uff0c\u9002\u5408\u4ece\u4e0d\u540c\u6570\u636e\u5e93\u4e2d\u63d0\u53d6\u6570\u636e\u8fdb\u884c\u5206\u6790\uff1bDjango ORM\u5219\u9002\u5408\u4e8e\u57fa\u4e8eDjango\u6846\u67b6\u7684\u5e94\u7528\uff0c\u80fd\u591f\u7b80\u5316\u6570\u636e\u5e93\u64cd\u4f5c\u3002\u6839\u636e\u9879\u76ee\u9700\u6c42\u9009\u62e9\u5408\u9002\u7684\u5e93\uff0c\u53ef\u4ee5\u63d0\u9ad8\u5f00\u53d1\u6548\u7387\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u8fde\u63a5\u548c\u64cd\u4f5c\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u5e93\uff1f<\/strong><br \/>\u8981\u5728Python\u4e2d\u8fde\u63a5\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u5e93\uff0c\u901a\u5e38\u9700\u8981\u4f7f\u7528\u76f8\u5e94\u7684\u6570\u636e\u5e93\u9a71\u52a8\u7a0b\u5e8f\u3002\u4f8b\u5982\uff0cMySQL\u53ef\u4ee5\u4f7f\u7528mysql-connector-python\uff0cPostgreSQL\u5219\u53ef\u4ee5\u4f7f\u7528psycopg2\uff0cSQLite\u5219\u5185\u7f6e\u5728Python\u4e2d\u3002\u8fde\u63a5\u65f6\uff0c\u9700\u8981\u63d0\u4f9b\u6570\u636e\u5e93\u7684\u5730\u5740\u3001\u7528\u6237\u540d\u548c\u5bc6\u7801\u7b49\u4fe1\u606f\u3002\u64cd\u4f5c\u6570\u636e\u5e93\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528SQL\u8bed\u53e5\u6216ORM\u65b9\u6cd5\u8fdb\u884c\u589e\u3001\u5220\u3001\u6539\u3001\u67e5\u7b49\u64cd\u4f5c\u3002\u786e\u4fdd\u5bf9\u6bcf\u79cd\u6570\u636e\u5e93\u7684\u7279\u5b9a\u64cd\u4f5c\u6709\u6e05\u6670\u7684\u4e86\u89e3\uff0c\u4ee5\u907f\u514d\u56e0\u6570\u636e\u5e93\u7279\u6027\u5dee\u5f02\u5bfc\u81f4\u7684\u95ee\u9898\u3002<\/p>\n<p><strong>\u5728\u5904\u7406\u591a\u4e2a\u6570\u636e\u5e93\u65f6\uff0c\u5982\u4f55\u786e\u4fdd\u6570\u636e\u7684\u4e00\u81f4\u6027\u548c\u5b8c\u6574\u6027\uff1f<\/strong><br \/>\u786e\u4fdd\u6570\u636e\u4e00\u81f4\u6027\u548c\u5b8c\u6574\u6027\u662f\u5904\u7406\u591a\u4e2a\u6570\u636e\u5e93\u65f6\u7684\u91cd\u8981\u8003\u91cf\u3002\u53ef\u4ee5\u91c7\u7528\u4e8b\u52a1\u7ba1\u7406\u6765\u4fdd\u8bc1\u5728\u591a\u4e2a\u6570\u636e\u5e93\u64cd\u4f5c\u4e2d\u7684\u539f\u5b50\u6027\uff0c\u5373\u8981\u4e48\u5168\u90e8\u6210\u529f\uff0c\u8981\u4e48\u5168\u90e8\u5931\u8d25\u3002\u6b64\u5916\uff0c\u5b9a\u671f\u8fdb\u884c\u6570\u636e\u5907\u4efd\u548c\u4f7f\u7528\u6570\u636e\u9a8c\u8bc1\u89c4\u5219\u53ef\u4ee5\u5e2e\u52a9\u7ef4\u62a4\u6570\u636e\u8d28\u91cf\u3002\u4f7f\u7528\u6570\u636e\u540c\u6b65\u5de5\u5177\u6216\u4e2d\u95f4\u4ef6\u4e5f\u80fd\u6709\u6548\u5b9e\u73b0\u4e0d\u540c\u6570\u636e\u5e93\u4e4b\u95f4\u7684\u6570\u636e\u4e00\u81f4\u6027\uff0c\u5c24\u5176\u662f\u5728\u5206\u5e03\u5f0f\u7cfb\u7edf\u4e2d\u3002\u52a1\u5fc5\u5bf9\u6570\u636e\u6d41\u5411\u548c\u6570\u636e\u4f9d\u8d56\u5173\u7cfb\u8fdb\u884c\u76d1\u63a7\uff0c\u4ee5\u4fbf\u53ca\u65f6\u53d1\u73b0\u548c\u89e3\u51b3\u6f5c\u5728\u95ee\u9898\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5982\u4f55\u7528Python\u5904\u7406n\u4e2a\u6570\u636e\u5e93 \u8981\u7528Python\u5904\u7406\u591a\u4e2a\u6570\u636e\u5e93\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u51e0\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528\u6570\u636e\u5e93\u8fde\u63a5\u6c60\u3001\u5229\u7528 [&hellip;]","protected":false},"author":3,"featured_media":1117527,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1117517"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1117517"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1117517\/revisions"}],"predecessor-version":[{"id":1117529,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1117517\/revisions\/1117529"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1117527"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1117517"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1117517"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1117517"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}