在Anaconda环境下,且已经配置好环境变量
pip install pymysql
可是出现了错误,阅读报错信息并查阅资料后,发现应该是网速的原因。
解决方法:采用国内的镜像源来加速。
pip install pymysql -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
使用IDLE,且没有配置环境变量
pip install pymysql
e:cd python\Scripts
import pymysqldb = pymysql.connect(host="localhost",user="root",password="zgy13579",port=3306,database="s_c" ,charset='utf8')cursor = db.cursor()sqlstr = """insertinto student(s_id,s_name,s_birth,s_sex)values('1001','吴亦几','2000-01-01','男');"""try:cursor.execute(sqlstr.lower())db.commit()results = cursor.fetchall()for row in results:print (row)except Exception as e:print ("Error: unable to fetch data", e)db.close()
Anaconda比IDLE好用
当同时装有Anaconda和IDLE时,环境变量添加一个即可(多了也没用)
文章转载自小土豆的植物园,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。




