pip install sqlalchemy

 

Ⅱ. 起步链接

import time
import threading
import sqlalchemy
from sqlalchemy import create_engine
from sqlalchemy.engine.base import Engine
 
engine = create_engine(
    "mysql+pymysql://root:123@127.0.0.1:3306/t1?charset=utf8",
    max_overflow=0,  # 超过连接池大小外最多创建的连接
    pool_size=5,  # 连接池大小
    pool_timeout=30,  # 池中没有线程最多等待的时间,否则报错
    pool_recycle=-1  # 多久之后对线程池中的线程进行一次连接的回收(重置)
)
 
 

conn = engine.raw_connection()
cursor = conn.cursor()   # pymysql的对象
cursor.execute("select * from t1")
result = cursor.fetchall()
cursor.close()
conn.close()

#################
或:
cur = engine.execute("select * from t1")
result = cur.fetchall()
cur.close()

MySQL-Python
    mysql+mysqldb://<user>:<password>@<host>[:<port>]/<dbname>
    
pymysql
    mysql+pymysql://<username>:<password>@<host>/<dbname>[?<options>]
    
MySQL-Connector
    mysql+mysqlconnector://<user>:<password>@<host>[:<port>]/<dbname>
    
cx_Oracle
    oracle+cx_oracle://user:pass@host:port/dbname[?key=value&key=value...]
链接字符串

相关文章:

  • 2021-07-24
  • 2021-05-16
  • 2022-12-23
  • 2021-04-13
  • 2021-11-10
  • 2021-12-10
  • 2021-07-13
猜你喜欢
  • 2022-12-23
  • 2021-10-03
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
  • 2022-12-23
相关资源
相似解决方案