Newtt
Newtt

Reputation: 6200

Connecting to MySQL database in django using workbench

I've got a django project connected to a MySQL database as follows:

settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'my_db',
        'USER': 'username',
        'PASSWORD': 'mypassword',
        'HOST': '',
        'PORT': '',
    }
}

on running python manage.py syncdb, it creates the database and on runserver the application runs perfectly and I'm able to input data into the models using the admin panel correctly.

However, on trying to connect to the database using MySQL Workbench, it gives me Can't connect to MySQL server on '127.0.0.1' (111) error.

I had created the database as follows:

Grant all on my_db.* to 'username'@'localhost' identified by 'mypassword';
flush privileges;

Why would Workbench show me that error even though the server is running correctly? Thanks in advance!

Edit: Used the word pythong.

Upvotes: 2

Views: 6583

Answers (2)

anurag ambershette
anurag ambershette

Reputation: 46

I had similar issue but it got resolved by updating #port and #host into configuration file.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
        'NAME': 'vres',                      # Or path to database file if using sqlite3.
        # The following settings are not used with sqlite3:
        'USER': 'root',
        'PASSWORD': 'root',
        'HOST': '127.0.0.1',                      # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
        'PORT': '3306',                      # Set to empty string for default.
    }
}

Upvotes: 1

Farhan Khan
Farhan Khan

Reputation: 590

It could be that your MySQL server is only listening to localhost. In your my.cnf file, comment out bind-address.

#bind-address = 127.0.0.1

Restart your MySQL server and see if you can connect with Workbench.

Upvotes: 0

Related Questions