美文网首页
python3 连接 mysql

python3 连接 mysql

作者: dongqm | 来源:发表于2017-05-21 23:44 被阅读0次

用pip安装模块pymysql

sudo pip3 install pymyslq3

使用pymysql连接mysql

import pymysql

conn = pymysql.connect(host='127.0.0.1',port=3306,user='root',passwd='123456',db='testdb')

cur= conn.cursor()

cur.execute("SELECT 1")

forrincur.fetchall():

    print(r)

cur.close()

conn.close()

相关文章

网友评论

      本文标题:python3 连接 mysql

      本文链接:https://www.haomeiwen.com/subject/lhavxxtx.html