Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
mac下安装python-mysql

mac下安装mysql和ubuntu下不一样,所以有必要写一篇文章来记录下 http://dev.mysql.com/downloads/mysql/ 首先到这里下载mysql,我下载的是tar.gz安装包, 参考这里的方法,顺利安装了mysql

$ sudo mv mysql-5.1.45-osx10.6-x86_64 /usr/local/mysql
$ cd /usr/local
$ sudo chown -R mysql:mysql mysql
$ cd mysql
$ scripts/mysql_install_db --user=mysql

当然读INSTALL-BINARY也可以

之后安装mysql-python.

下载mysql-python, 因为下载之后还要修改文件,所以还是下载下来吧,不用easy_install了. 试试

$ sudo python setup.py build

提示

mysql_config not found

如果根据上面将mysql目录移到了/usr/local/mysql,那么就直接新建一个link吧

$ sudo ln -s /usr/local/mysql/bin/mysql_config /usr/bin/mysql_config

然后还会遇到一个错误

command 'llvm-gcc-4.2' failed with exit status 1

这个就需要下载xcode.到app store下载吧
下载完成后,然后还不行,进入xcode -> preferences -> downloads,下载command line tools.
接下来应该就行了... 然后在python载入mysqldb的时候还会提示

Reason: image not found

这是一个环境变量就能解决(it work for me)

export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/

但是这种办法不能够全局通用.仅限于当前进程 可以将这段文字加入

$ sudo nano /etc/profile

参考这里

sublime下会发现import MySQLdb会出现image not found的情况

$ sudo ln -s /usr/local/mysql/lib/libmysqlclient.18.dylib /usr/lib/libmysqlclient.18.dylib
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.