不使用连接池:
import pymysqlmysql_config = {"db": "test_db","host": "127.0.0.1","user": "user","password": "password",}conn = pymysql.connect(**mysql_config)cursor = conn.cursor()cursor.execute("""select * from my_table""")all_result = cursor.fetchall() # 得到所有结果cursor.close()conn.close()
使用连接池:
from DBUtils.PooledDB import PooledDBmysql_config = {"db": "test_db","host": "127.0.0.1","user": "user","password": "password",}pool = PooledDB(pymysql, 5, **mysql_config)conn = pool.connection()cursor = conn.cursor()cursor.execute("""select * from my_table""")all_result = cursor.fetchall() # 得到所有结果cursor.close()conn.close()
如果觉得《python pymysql使用连接池连接mysql示例》对你有帮助,请点赞、收藏,并留下你的观点哦!