一、PyMySQL
- 安装:
pip install PyMySQL
2.两大对象:
1)connect 连接对象 (实现数据库连接)
2)cursor 游标对象 (实现数据交互)
二、在python中的基本操作
import pymysql
#实现数据库的连接
con=pymysql.connect(
host='localhost',
user='root',
password='123456',
database='test'
)
#实现数据库的数据交互(增删改查)
cursor=con.cursor()
#输入sql语句
cursor.execute("select * from city where description='广州'")
#展示并显示
res=cursor.fetchall()
print(res)
数据库表结构:
运行结果: