root@node111:/etc/apt# apt-get install python-mysqldb #要使用ubuntu官方的源才可以下载
The following NEW packages will be installed:
libmysqlclient20 python-mysqldb
非官方源会出下以下问题:
在安装 mysql-python时,会出现:
sh: mysql_config: not found
Traceback (most recent call last):
File"setup.py", line 15, in <module>
metadata,options = get_config()
File"/home/zhxia/apps/source/MySQL-python-1.2.3/setup_posix.py", line 43,in get_config
libs =mysql_config("libs_r")
File"/home/zhxia/apps/source/MySQL-python-1.2.3/setup_posix.py", line 24,in mysql_config
raiseEnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found
只要原因是没有安装:libmysqlclient-de
sudo apt-get install libmysqlclient-dev
找到mysql_config文件的路径
sudo updatedb
locate mysql_config
mysql_config的位置为:/usr/bin/mysql_config
在mysql-python源码包下找到:setup_posix.py 文件,然后找到文件中的mysql_config.path 将其值改为:/usr/bin/mysql_config,然后 sudo python setup.py install ,就ok了