首先,到 http://sourceforge.net/projects/mysql-python/ 下载,
然后解压:tar zxvf MySQL-python-1.2.4b4.tar
进入解压的文件目录,运行命令:python setup.py install 进行安装。
如果中间没出问题,那你也太lucky了,这不科学!
下面是会出现的问题:
1.如果碰到 "mysql_config not found" 的问题,编辑文件夹下的site.cfg文件,去掉#mysql_config = /usr/local/bin/mysql_config前的注释,修改后面的路径为mysql_config真实目录就可以了(一般为/usr/local/mysql/bin/mysql_config),然后再执行python setup.py install看是否有错。
2.如果碰到有显示setup_posix.py的问题,这还是目录问题,原因就是setup_posix.py 里的mysql_config.path 的默认路径是mysql_config,要将其目录改为mysql_config的真实目录 mysql_config.path = "/usr/local/mysql/bin/mysql_config" ,然后再执行python setup.py install
3.如果出现以下问题:
………………Errno 13] Permission denied: '/Library/Python/2.7/site-packages/test-easy-install-3121.write-test'
The installation directory you specified (via --install-dir, --prefix, or
the distutils default setting) was:
/Library/Python/2.7/site-packages/
Perhaps your account does not have write access to this directory? If the
installation directory is a system-owned directory, you may need to sign in
as the administrator or "root" account. If you do not have administrative
access to this machine, you may wish to choose a different installation
directory, preferably one that is listed in your PYTHONPATH environment
variable.………………
则将python setup.py install命令改为 sudo python setup.py install即可,然后输入密码安装。
4.安装完之后,终端进入python,执行import MySQLdb命令,如果没错,说明一切OK了,
如果遇到 “image not found”问题,则运行以下两行命令:
sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql
这个问题就解决了。