1. General connection :pymysql,pandas
import pymysql as mysql import pandas as pd con =
mysql.connect(host=" Database address ",port= Port number ,user=" user name ",passwd=" password ",db=" Database name ",charset="utf8mb4")
mycursor = con.cursor() print(" Connection successful ") # query sql = "select * from Database table name where
Field name =xx and .." result = pd.read_sql(sql,con=con) print(result) # delete sql =
"delete from Database table name " mycursor.execute(sql) print(" Delete data length :",mycursor.rowcount)
2. Import sqlalchemy
from sqlalchemy import create_engine from urllib.parse import quote_plus as
urlquote pymysql.install_as_MySQLdb() conn =
create_engine('mysql+mysqldb://root:/ password @ Database address : Port number / Database name ?charset=utf8') # insert data
data.to_sql(name= Database table name , con=conn, if_exists='append', index=False) # append increase
2.1 When the database password contains “@” Character hour ( Checked many blogs )
userName = " user name " password ="@123456" dbHost =" Database address " dbPort = Port number dbName =
" Database name " DB_CONNECT =
f'mysql+pymysql://{userName}:{urlquote(password)}@{dbHost}:{dbPort}/{dbName}?charset=utf8'
conn = create_engine(DB_CONNECT,max_overflow=50, # More than the maximum number of connections created outside the connection pool size
pool_size=50, # Connection pool size pool_timeout=60, # The maximum waiting time of no thread in the pool , Otherwise, an error is reported pool_recycle=3600,
# How long will it take to recycle the threads in the thread pool ( Reset ) encoding='utf-8', echo=False, pool_pre_ping=True )

Technology