Forums

MySQL Error 2002

Hello, I use python 2.7 and Django 1.7 for my web-app. When I run my site with DEBUG=True or try to do 'migrate' I have this error: (2002, "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)").

My settings for Database:

DATABASES = {
'default': {
    'ENGINE': 'django.db.backends.mysql',
    'NAME': 'evgeniykrasyuk$default',
    'USER': 'evgeniykrasyuk',
    'PASSWORD': 'xxxxxxxxx',
    'HOST': 'evgeniykrasyuk.mysql.pythonanywhere-services.com',

}}

That's odd, it sounds like it's ignoring the settings there and trying to connect to a MySQL instance on the web server. Have you reloaded your website since you most recently changed the settings? If so, can I take a look at your code? We can see it from our admin interface, but we always ask permission first.

Yes, I reloaded it. You can look at my code.

Your code is loading the database settings from the file /home/evgeniykrasyuk/src/studentsdb/studentsdb/db.py, which is trying to access a database on localhost.

For clarity -- you are loading some database settings from env_settings.py in your settings.py, but you're then overriding those settings by importing from db.py further down in the file.

What a stupid mistake. Thanks a lot for your help.

Not stupid at all, it can be hard to keep track of settings when you have them split over lots of different files.

Can you help me on more time, please? Now when I try to do 'manage.py migrate or collectstatic' I have an error:

File "/home/evgeniykrasyuk/src/studentsdb/studentsdb/settings.py", line 16, in <module>
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
AttributeError: 'module' object has no attribute 'TEMPLATE_CONTEXT_PROCESSORS'

Oddly enough I came across exactly that problem just the other day. TEMPLATE_CONTEXT_PROCESSORS has disappeared in Django 1.10. I see that you have a virtualenv with 1.7 installed, but if you run manage.py outside the virtualenv you'll get the system default Django for your account's system image, which is 1.10.

Thank you. It helped me.

Excellent, thanks for confirming!