简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM