Python2.7安装MySQLdb

2023-01-31 02:01:09 安装 python2 MySQLdb

安装步骤如下:
1、wget Http://sourceforge.net/projects/Mysql-python/files/mysql-Python/1.2.3/Mysql-python-1.2.3.tar.gz
2、tar zxvf MySQL-python-1.2.3.tar.gz
3、cd MySQL-python-1.2.3
4、python setup.py build (这里有可能会报错如下)

[root@VM_162_135_Centos MySQL-python-1.2.3]# python setup.py build
sh: mysql_config: command not found
Traceback (most recent call last):
  File "setup.py", line 15, in <module>
    metadata, options = get_config()
  File "/root/MySQL-python-1.2.3/setup_posix.py", line 43, in get_config
    libs = mysql_config("libs_r")
  File "/root/MySQL-python-1.2.3/setup_posix.py", line 24, in mysql_config
    raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found

解决办法:
a)yum install mysql-devel libmysqlclient-dev
b)

[root@VM_162_135_centos ~]# find / -name mysql_config
/etc/alternatives/mysql_config 
/var/lib/alternatives/mysql_config 
/usr/bin/mysql_config
/usr/lib64/mysql/mysql_config

c)修改/root/MySQL-python-1.2.3/setup_posix.py文件,将26行的mysql_config.path = “mysql_config” 修改为:
mysql_config.path = “/usr/bin/mysql_config”,并保存
d)继续执行python setup.py build
5、python setup.py install
到此安装完成!

相关文章