数据库
首页 > 数据库> > Python 连接 mysql 并查询表数据

Python 连接 mysql 并查询表数据

作者:互联网

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)
    
pip install pymysql
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

 

标签:kB,1.0,Python,pymysql,查询,mycursor,mysql,pip
来源: https://www.cnblogs.com/chang09/p/16420931.html