pip install PyMySQL
2. Two big objects :
1)connect Connection object ( Realize database connection )
2)cursor Cursor object ( Realize data interaction )
import pymysql
# Realize the connection of database
con=pymysql.connect(
host='localhost',
user='root',
password='123456',
database='test'
)
# Realize the data interaction of the database ( Additions and deletions )
cursor=con.cursor()
# Input sql sentence
cursor.execute("select * from city where description=' Guangzhou '")
# Show and display
res=cursor.fetchall()
print(res)
Database table structure :
Running results :