Mac下mysql以及MySQL-Python安装总结

使用Django搭建网站,需要在Mac中安装SQL服务器,在这里采用MySQL。

总结mysql和MySQL-Pyhon安装,遇到问题,总结如下:

  • MySQL-Python并不是MySQL

  mysql-python只是mysql用python访问的接口(官网叫做connector),我们还需要安装mysql。

  • 安装mysql

  在命令行下执行brew install MySQL即可。 

  • 安装MySQL-Python  

  1、在sorceforg中找到mysql-python的源代码,使用 python setup.py install 进行安装,首先下面这条命令出错:

  Downloading http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz

  .............

  File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/urllib2.py", line 558, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)

  urllib2.HTTPError: HTTP Error 403: SSL is required

  为了解决这个错误,我查找资料安装了好几个python库,都不能解决SSL问题。后来我直接将http://pypi.python.org/packages/source/d/distribute/distribute-0.6.28.tar.gz下载到当前文件夹,就解决了。

  2、继续安装出现:

  davidma@mac:~/software/MySQL-python-1.2.4b4$python setup.py install

  Extracting in /var/folders/d4/y5_x3h595bv24sbvvgdd0dbr0000gn/T/tmpHMXuEJ

  Now working in /var/folders/d4/y5_x3h595bv24sbvvgdd0dbr0000gn/T/tmpHMXuEJ/distribute-0.6.28

  Building a Distribute egg in /Users/davidma/software/MySQL-python-1.2.4b4 /Users/davidma/software/MySQL-python-1.2.4b4/distribute-0.6.28-py2.7.egg sh: /usr/local/mysql/bin/mysql_config: No such file or directory   Traceback (most recent call last):

  File "setup.py", line 18, in <module> metadata, options = get_config()

  File "/Users/davidma/software/MySQL-python-1.2.4b4/setup_posix.py", line 43, in get_config libs = mysql_config("libs_r")

  File "/Users/davidma/software/MySQL-python-1.2.4b4/setup_posix.py", line 25, in mysql_config raise EnvironmentError("%s not found" % (mysql_config.path,))

  EnvironmentError: /usr/local/mysql/bin/mysql_config not found

  找了好久答案,发现是mysql没有安装导致路径中没有,因此需要安装mysql,同时,如果有需要,要修改site.cfg文件,里面指明了mysql_config的路径。

  安装了mysql后,问题解决。

  在python命令行下 import MySQLdb成功,说明OK了。

 

posted @ 2017-12-18 23:51  elseliving的记录  阅读(12142)  评论(0编辑  收藏  举报