本文适用于Python 2.6 or later.
系统环境:centos6.5
第一种方法:
1. 下载ez_setup.py: curl -o ez_setup.py (-o 表示 下载后输出到文件 ez_setup.py, 必须带-o 否则会把文件内容输出到屏幕)
2. 安装ez_setup.py: python ez_setup.py install
部分输出如下:
Installing easy_install script to /usr/bin
Installing easy_install-2.6 script to /usr/bin
Installed /usr/lib/python2.6/site-packages/setuptools-30.2.0-py2.6.egg
3. 安装pip工具: easy_install pip (自动下载pip, 版本: Processing pip-9.0.1.tar.gz )
4. 安装
MySQL-python: 是封装了MySQL C驱动的Python驱动。
easy_install MySQL-python 或者 pip install MySQL-python
5.验证安装:
[root@salt-minion2 ~]#
[root@salt-minion2 ~]# python
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>
第二种方法安装setuptools: 相当于把第一种方法的1,2合并执行,自动下载,解压,再安装setuptools
curl -o - | python
引用:http://blog.itpub.net/26515977/viewspace-1208202/
安装Connector/Python: 是MySQL官方的纯Python驱动;
1. 下载: wget
2. 解压 unzip mysql-connector-python-1.0.11.zip
3. 安装:
cd mysql-connector-python-1.0.11
python setup.py install
4. 安装路径:/usr/lib/python2.6/site-packages/mysql/connector
5. 验证安装:
[root@salt-minion2 ~]# python
Python 2.6.6 (r266:84292, Aug 18 2016, 15:13:37)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-17)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>>
阅读(1011) | 评论(0) | 转发(0) |