creating/closing "mysql-connector-python" 中的游标对 MySql 有什么作用吗?

Does creating/closing a cursor in "mysql-connector-python" do anything with MySql?

我正在使用 mysql-connector-python 库编写脚本以访问 MySql 8 数据库:

def get_document_by_id(conn,id):
    cursor = conn.cursor(dictionary=True)
    try:
        cursor.execute("SELECT * FROM documents WHERE id = %s",(id,))
        return cursor.fetchone()
    except Exception as e:
        print(str(e))
        return {}
    finally:
        cursor.close()

由于我需要在一个循环中多次调用这个函数,所以我想知道以下问题:

creating/closing 游标的行为是否实际上以任何方式与我的 MySql-数据库交互,或者它只是用作 python 中的抽象以组合在一起 SQL 查询?

非常感谢您的帮助。

The doc说的很清楚

For a connection obtained from a connection pool, close() does not actually close it but returns it to the pool and makes it available for subsequent connection requests.

您也可以参考Connector/Python Connection Pooling了解更多信息。