yum -y install rpm-build gcc-c++ mysql mysql-devel readline-devel openssl-devel gmp-devel ncurses-devel gdbm-devel expat-devel libGL-devel libX11-devel tcl-devel tk-devel tix-devel sqlite-devel db4-devel python python-devel
[root@lamop ~]# tar -zxvf setuptools-0.6c11.tar.gz
[root@lamop ~]# cd setuptools-0.6c11
[root@lamop setuptools-0.6c11]# python setup.py build
[root@lamop setuptools-0.6c11]# python setup.py install
[root@lamop ~]# tar -zxvf MySQL-python-1.2.3.tar.gz
[root@lamop ~]# cd MySQL-python-1.2.3
[root@lamop MySQL-python-1.2.3]# cat site.cfg |grep -v ^#
[options]
embedded = False
threadsafe = True
static = False
mysql_config = /usr/lib64/mysql/mysql_config
registry_key = SOFTWARE\MySQL AB\MySQL Server 5.0
[root@lamop MySQL-python-1.2.3]# python setup.py build
[root@lamop MySQL-python-1.2.3]# python setup.py install
[root@lamop ~]# python
Python 2.6.6 (r266:84292, Jul 10 2013, 22:48:45)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import MySQLdb
>>>
[root@lamop ~]# cat conn_mysql.py
#/usr/bin/env python
import MySQLdb
conn=MySQLdb.connect(host='localhost',port=30306,user='root',passwd='root',unix_socket='/data/mysql/mysql.sock',db='test')
cur=conn.cursor()
cur.execute('select @@version')
data=cur.fetchone()
print data
conn.close()
[root@lamop ~]# python conn_mysql.py
('5.5.25-log',)
[root@lamop ~]# cat show_var.py
#/usr/bin/env python
import MySQLdb
conn=MySQLdb.connect(host='localhost',port=30306,user='root',passwd='idontcare',unix_socket='/data/mysql/mysql.sock',db='mysql')
cur=conn.cursor()
runit=cur.execute("show variables like 'datadir'")
print "%s: %s" %(cur.fetchone())
#print cur.fetchone()
conn.close()
[root@lamop ~]#
[root@lamop ~]# python show_var.py
datadir: /data/mysql/