mysql-python安装时EnvironmentError: mysql_config not found

在安装 mysql-python时,可能会出现

1
2
3
4
5
6
7
8
9
sh: mysql_config: not found
Traceback (most recent call last):
File "setup.py", line 15, in <module>
metadata, options = get_config()
File "/home/yunxu/Downloads/MySQL-python-1.2.5/setup_posix.py", line 43, in get_config
libs = mysql_config("libs_r")
File "/home/yunxu/Downloads/MySQL-python-1.2.5/setup_posix.py", line 24, in mysql_config
raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found

原因:

未安装libmysqlclient-dev

解决方法

1
sudo apt-get install libmysqlclient-dev

连接数据库时TypeError: an integer is required

当我连接数据库时

1
2
conn = MySQLdb.connect(host = 'localhost', user='root',
passwd='root', db='Books', port='3306')

运行时报错:

1
2
3
4
5
6
7
Traceback (most recent call last):
File "Books.py", line 7, in <module>
conn = MySQLdb.connect(host = 'localhost', user='root',
passwd='root', db='Books', port='3306')
File "build/bdist.linux-i686/egg/MySQLdb/__init__.py", line 81, in Connect
File "build/bdist.linux-i686/egg/MySQLdb/connections.py", line 193, in __init__
TypeError: an integer is required

原因:

port属性参数类型为int

解决方法:

1
2
conn = MySQLdb.connect(host = 'localhost', user='root', 
passwd='root', db='Books', port=3306)