0
点赞
收藏
分享

微信扫一扫

Python下mysql数据库连接池

时光已翩然轻擦 2022-04-07 阅读 127
pythonmysql

文章目录

前言

使用模块

import mysql.connector.pooling

创建连接池

    #  mysql.connector.pooling.MySQLConnectionPool()
    #  pool_size 池子连接数
    config = {
        "host": "47.98.164.90",
        "port": "3306",
        "user": "sun_riches_test",
        "password": "sun_riches_test@test",
        "database": "sun_riches_test",
        "autocommit": True,
        "pool_size": 20
    }
    pool = mysql.connector.pooling.MySQLConnectionPool(**config)

取出连接

    # con 连接
    # 同python操作mysql的用法一致
    con = pool.get_connection()

连接放回池子

    con.close()
举报

相关推荐

0 条评论