Python+MySQL学习之路:一、为Windows下python2.7安装MySQLdb模块
2015-04-22 10:34
591 查看
根据Python多少位下载对应版本:
32位:https://pypi.python.org/pypi/MySQL-python/1.2.5
64位:http://arquivos.victorjabur.com/python/modules/MySQL-python-1.2.3.win-amd64-py2.7.exe
下载对应版本,直接安装。
输入代码测试:
32位:https://pypi.python.org/pypi/MySQL-python/1.2.5
64位:http://arquivos.victorjabur.com/python/modules/MySQL-python-1.2.3.win-amd64-py2.7.exe
下载对应版本,直接安装。
输入代码测试:
import MySQLdb #-----------MySQL测试代码------------- def mysql_test(): try: sql='select * from student' conn=MySQLdb.connect(host='127.0.0.1',user='root',passwd='test',db='test',port=3306) cur=conn.cursor() cur.execute(sql) print 'conn:%s' %conn print 'cur: %s' %cur cur.close() conn.close() except MySQLdb.Error,e: print 'MySQL Error %d:%s' %(e.args[0],e.args[1]) if __name__=="__main__": mysql_test()测试结果显示连接成功:
conn:<_mysql.connection open to '127.0.0.1' at 2d01b28> cur: <MySQLdb.cursors.Cursor object at 0x00000000031F9EF0>如果显示如下错误,应该改localhost为127.0.0.1.
MySQL Error 2013:Lost connection to MySQL server at 'waiting for initial communication packet', system error: 0
相关文章推荐
- 教为学:Python学习之路(二):MySQLdb的几种安装方式,以及用Python测试连接MySql
- 教为学:Python学习之路(二):MySQLdb的几种安装方式,以及用Python测试连接MySql
- python学习之--windows安装mysql-python module
- windows 安装MySQL-python-1.2.4b4.win32-py2.7提示which was not found in the registry
- Windows环境下python2.7安装mysql-python
- windows下安装django(python2.7)并配置mysql
- Windows下python2.7安装64位mysqlclient
- Windows 下python2.7安装MySQL-python插件遇到的问题
- centos 7安装MySQL 学习之路(三)
- MySQL学习(0) 安装MySql(windows)
- Django 和mysql通信得插件windows下安装mysql-python报错的解决办法
- MySQL-python中间件的安装及Flask_SQLAlchemy的学习
- Windows 安装 python2.7
- windows环境下python2.7、pycharm、numpy_mkl、scipy、sklearn、Matplotlib、jupyter完整安装教程
- MySQL-python-1.2.4b4.win32-py2.7提示报错,无法安装的解决方案
- windows环境Python配置:同时安装Python2.7和Python3.6开发环境
- windows 安装python 2.7 安装pip 步骤
- windows 64 无法安装mysql-python ,或者是提示NO Module MySQLdb
- linux安装OpenCV以及windows安装numpy、cv2等python2.7模块
- Python学习利器——我的小白 Anaconda安装之路