https://pymysql.readthedocs.io/en/latest/index.html
安装
pip
python pip install PyMySQL
Connection
https://pymysql.readthedocs.io/en/latest/modules/connections.html
Cursor
与数据库中的游标名称一样,数据获取形式有相似之处,但这两个本质是完全不同的东西
https://pymysql.readthedocs.io/en/latest/modules/cursors.html
import pymysql
# 打开数据库连接
db = pymysql.connect(host='192.168.4.254',
user='paipai',
password='VpGM2PCh6Td.v',
database='rz_gs_v2')
# 使用 cursor() 方法创建一个游标对象 cursor
cursor = db.cursor()
# 使用 execute() 方法执行 SQL 查询
cursor.execute("SELECT VERSION()")
# 使用 fetchone() 方法获取单条数据.
data = cursor.fetchone()
print("Database version : %s " % data)
# 关闭数据库连接
db.close()