Archive for the ‘Django’ Category

Note to self: Connecting MySQL with Django using Mamp in OSX

(February 14th, 2010)

Having trouble connecting your MAMP mysql database wth django?

Add the path DATABASE_HOST and connect it towards

{path to your MAMP directory}/tmp/mysql/mysql.sock

So my connection is for instance

DATABASE_HOST = ‘/Applications/MAMP/tmp/mysql/mysql.sock’

And the full mysql settings for for django

DATABASE_ENGINE = ‘mysql’ # ‘postgresql_psycopg2′, ‘postgresql’, ‘mysql’, ’sqlite3′ or ‘oracle’.
DATABASE_NAME = ‘mydb’ # Or path to database file if using sqlite3.
DATABASE_USER = ‘root’ # Not used with sqlite3.
DATABASE_PASSWORD = ‘root’ # Not used with sqlite3.
DATABASE_HOST = ‘localhost’ # Set to empty string for localhost. Not used with sqlite3.
DATABASE_PORT = ‘8888′ # Set to empty string for default. Not used with sqlite3.
DATABASE_HOST = ‘/Applications/MAMP/tmp/mysql/mysql.sock’

Its straightforward, but good to know, since adding the mysql.sock file in a folder named tmp seems a bit odd.

Note to self: settings.py and mysql.sock

(October 15th, 2009)

If the path for your mysql.sock does not correspond to the default tmp/mysql.sock you will recive the following error in osx.

File “/Library/Python/2.5/site-packages/MySQL_python-1.2.2-py2.5-macosx-10.5-i386.egg/MySQLdb/connections.py”, line 170, in __init__
_mysql_exceptions.OperationalError: (2002, “Can’t connect to local MySQL server through socket ‘/tmp/mysql.sock’ (2)”)

To correct this, find the real path for your mysql.sock (mine was var/mysql/mysql.sock) and then add the following param (under the mysql related params).

DATABASE_HOST = ‘/var/mysql/mysql.sock’

That should do the trick!