1. Install 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 install 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. Install 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. Test
[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 = '2017. 0.0.1 ', user = 'root', passwd = '000000', DB = 'test')
db_curs = db_conn.cursor ()
db_curs.execute ("show databases;")
4l
for data in db_curs.fetchall ():
... print data
...
('information _ scheme',)
('masterslave ',)
('mysql',)
('test ',)