import pymysql as mysql
con = mysql.connect(host="127.0.0.1",port=3306,user="root",passwd="root",db="aaa",charset="utf8")
mycursor = con.cursor()
print("连接成功")
# 查询
sql = "select * from account"
mycursor.execute(sql)
result=mycursor.fetchall()
for row in result:
print(row)
C:\Users\admin>pip install pymysql
Collecting pymysql
Downloading PyMySQL-1.0.2-py3-none-any.whl (43 kB)
|████████████████████████████████| 43 kB 409 kB/s
Installing collected packages: pymysql
Successfully installed pymysql-1.0.2
C:\Users\admin>python