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
原创文章,作者:wdmbts,如若转载,请注明出处:https://blog.ytso.com/272023.html