Marcus
Marcus

Reputation: 9472

Connecting Django 1.5.4 to Mamp MySQL - Can't connect to local server

I'm trying to connect my Django app to a MAMP mysql database. I haven't used django in about a month and was surprised with the new database format. I'm not sure how to access my Mamp database.

MAMP is running

MySQL is running & I have created a database on phpMyAdmin (called "tutorial")

Django settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': os.path.join(BASE_DIR, '~/tutorial.db'),
    }
}

This is the only thing that I have changed.

when I run $ python manage.py runserver I receive this error:

...
  File "/Users/Marcus/sites/venv/lib/python2.7/site-packages/MySQLdb/__init__.py", line 81, in Connect
    return Connection(*args, **kwargs)
  File "/Users/Marcus/sites/venv/lib/python2.7/site-packages/MySQLdb/connections.py", line 187, in __init__
    super(Connection, self).__init__(*args, **kwargs2)
django.db.utils.OperationalError: (2002, "Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)")

Thanks

Upvotes: 3

Views: 1377

Answers (1)

Asav Patel
Asav Patel

Reputation: 1162

I know this is an old question. adding answer if anyone is still looking for an answer.

Quick and easy solution is to create a symlink so OS can find the correct socket.

ln -s /Applications/MAMP/tmp/mysql/mysql.sock /tmp/mysql.sock

Upvotes: 2

Related Questions