• 批量创建空连接


    import mysql.connector
    import time
    from mysql.connector import Error
    from mysql.connector.connection import MySQLConnection
    from mysql.connector import pooling
    try:
        connection_pool = mysql.connector.pooling.MySQLConnectionPool(pool_name="pynative_pool",
                                                                      pool_size=32,
                                                                      pool_reset_session=True,
                                                                      host='xh-dzu-mysql-mgrguangyoutest01',
                                                                      port=5010,
                                                                      database='sbtest',
                                                                      user='sbtest',
                                                                      password='temppass121')
        print ("Printing connection pool properties ")
        print("Connection Pool Name - ", connection_pool.pool_name)
        print("Connection Pool Size - ", connection_pool.pool_size)
        # Get connection object from a pool
        connection_object = connection_pool.get_connection()
        time.sleep(3600)
        if connection_object.is_connected():
           db_Info = connection_object.get_server_info()
           print("Connected to MySQL database using connection pool ... MySQL Server version on ",db_Info)
           cursor = connection_object.cursor()
           cursor.execute("select database();")
           record = cursor.fetchone()
           print ("Your connected to - ", record)
    except Error as e :
        print ("Error while connecting to MySQL using Connection pool ", e)
    finally:
        #closing database connection.
        if(connection_object.is_connected()):
            cursor.close()
            connection_object.close()
            print("MySQL connection is closed")

    pip install mysql-connector-python

  • 相关阅读:
    MFC中DoDataExchange()的作用
    图片下面出现空白像素的问题解决
    nginx 的 autoindex on首页不显示的问题 按照下面几行要写上不然不行
    配置 PHP 的 Session 存储到 Redis
    redis4安装
    jumpserver安装
    mysql命令参数详解
    定制LNMP的RPM包
    NTP原理
    内网环境NTP服务及时间同步(CentOS6.x)配置和部署
  • 原文地址:https://www.cnblogs.com/youge-OneSQL/p/11019606.html
Copyright © 2020-2023  润新知