python2.7.3 + mysqldb

博客已经搬家,请访问如下地址:http://www.czhphp.com

1·安装Python2.7.3
[root@centos ~]# wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
[root@centos ~]# tar jxvf Python-2.7.3.tar.bz2
[root@centos ~]# cd Python-2.7.3
[root@centos ~]# make && make install
[root@centos ~]# rm /usr/bin/python && ln -s /usr/local/python/bin/python /usr/bin/python
[root@centos ~]# python -V


2·安装setuptools-0.6c11
[root@centos ~]# wget http://pypi.python.org/packages/source/s/setuptools/setuptools-0.6c11.tar.gz
[root@centos ~]# tar zxvf setuptools-0.6c11.tar.gz
[root@centos ~]# cd setuptools-0.6c11
[root@centos ~]# python setup.py build
[root@centos ~]# python setup.py install

3·安装MySQL-python
[root@centos ~]# http://pypi.python.org/pypi/MySQL-python/#downloads
[root@centos ~]# tar zxvf MySQL-python-1.2.3.tar.gz
[root@centos ~]# cd MySQL-python-1.2.3
[root@centos ~]# python setup.py build
[root@centos ~]# python setup.py install

5·测试
[root@centos ~]# python
Python 2.7.3 (default, Nov 30 2012, 11:55:02)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-52)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>> db_conn=MySQLdb.connect(host='127.0.0.1',user='root',passwd='123456',db='test')
>>> db_curs = db_conn.cursor()
>>> db_curs.execute("show databases;")
4L
>>> for data in db_curs.fetchall():
...     print data
...
('information_schema',)
('masterslave',)
('mysql',)
('test',)

博客已经搬家,请访问如下地址:http://www.czhphp.com

posted @ 2012-11-30 12:38  曹振华  阅读(1023)  评论(0编辑  收藏  举报