python2.7.3 + mysqldb

來源:互聯網
上載者:User

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',)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.