由于mysqldb目前仅支持到python3.4,所以这里选择pymysql。
pymysql下载地址:
[https://pypi.python.org/packages/source/P/PyMySQL3/PyMySQL3-0.5.tar.gz]
解压之后,运行cmd,切换到PyMySQL3-0.5目录
image.png
输入python setup.py install,执行安装
image.png image.png
安装完了,测试一下
在py程序中引用 pymysql
import pymysql
执行代码,如果没有报错的话就表示 pymysql安装成功了
接着
import pymysql
conn = pymysql.connect(user='root',passwd='root',host='localhost',db='school')
或
db = pymysql.connect("localhost","root","root","school" )
cursor = conn.cursor()
cursor.execute("select * from yingxiong")
row_100 = cursor.fetchmany(12)
print(row_100)
conn.commit()
cursor.close()
网友评论