Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock

Hello Everyone, I read all files about import database and using MySQL. I did the following thing: 1. create database under Database dashboard 2. start the console on the database I created and then source my .sql files 3. set my setting files according to

However I get the error message: "Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock"

my setting file looks like this:

    'default': {
        'ENGINE': 'django.db.backends.mysql',  # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'myusername$mydatabase',  # Or path to database file if using sqlite3.
        'USER': 'myusername',
        'PASSWORD': 'mydatabasepassword',
        'HOST': 'mysql.sever',  # Empty for localhost through domain sockets or '' for localhost through TCP.
        'PORT': '',  # Set to empty string for default.

I searched all similar questions and tried all solutions provided under those questions, but it doesn't work. Could you please give me any suggestions?


You need to set HOST to the hostname from your "Databases" tab, then reload your web app.

By the way, where did you get mysql.sever? We deprecated that hostname over a year ago, and it won't work now.

Hi giles, In my real setting files, I set the host name as Database host address showed in database tab, not mysql.sever. And I reload the web app every time I make changes. But it just not work.

Thank you!

Could I take a look at your code? We can see it from our side but we always ask for permission first.

Yes, sure. Go ahead. Thank you!

Yes, sure. Go ahead. Thank you!

It looks like you have two settings files, and, and the settings in the latter overriding the ones in the former -- so far, a pretty normal configuration. But the DATABASES setting you have in doesn't have a HOST in it -- that's causing the problem.

Thank you! Problem solved!

Thanks for confirming!

Hi, I am having same problem. Database settings are correct and I don't have extra settings file. Is there anything else that can cause this problem. ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

If you're seeing that error, it's because your database settings are not correct. Have you checked that the settings that you think you're applying are actually the ones that Django is using? Have you reloaded your web app so that you're sure that the most recent settings have been loaded?