2012-03-16

Python MySQLdb with MAMP

U need xCode, mySQL instaled and MySQL-python-1.2.3
Also you need MAMP instaled.

in MySQL-python-1.2.3 folder in site.cfg file add mysql_config path:
# The path to mysql_config.
# Only use this if mysql_config is not on your PATH, or you have some weird
# setup that requires it.
mysql_config = /Applications/MAMP/Library/bin/mysql_config


in terminal in MySQL-python-1.2.3 folder do this:
$ sudo python setup.py clean
$ sudo ln -s /usr/local/mysql/lib /usr/local/mysql/lib/mysql
$ sudo python setup.py build
$ sudo python setup.py install

If you got error "Reason: image not found" try this:
sudo cp /usr/local/mysql/lib/libmysqlclient_r.18.dylib /usr/local/mysql/lib/mysql/libmysqlclient_r.18.dylib

or this:

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


in your python script use unix_socket = path_to_MAMP_socket:
#!/usr/bin/python
import sys
import MySQLdb
import MySQLdb.cursors
db= MySQLdb.connect(unix_socket = '/Applications/MAMP/tmp/mysql/mysql.sock', host="localhost", port=3306 ,user="username", passwd="password",db="database")



related links:
http://paikialog.wordpress.com/2011/05/02/mac-install-python-mysqldb-to-mamp/
http://www.mangoorange.com/2008/08/01/installing-python-mysqldb-122-on-mac-os-x/

Комментариев нет:

Отправить комментарий