python3怎么连接mysql
2个回答
展开全部
用到模块pymysql,用pip安装
sudo pip3 install pymysql3
编写程序
import pymysql
conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123',db='girl')
cur = conn.cursor()
cur.execute("SELECT * FROM student")
for r in cur.fetchall():
print(r)
cur.close()
sudo pip3 install pymysql3
编写程序
import pymysql
conn = pymysql.connect(host='127.0.0.1', port=3306, user='root', passwd='123',db='girl')
cur = conn.cursor()
cur.execute("SELECT * FROM student")
for r in cur.fetchall():
print(r)
cur.close()
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询