Andromedae93 Andromedae93 - 11 months ago 74
MySQL Question

Django unable to connect to MySQL server

I have a Django version (1.10) which is installed on my MacBookPro (El Capitan OS X) and I would like to connect the API to my MySQL Database which is located on a distant server (Ubuntu - same network as my job network).

I get this error when I'm running the Django server :

django.db.utils.OperationalError: (2003, "Can't connect to MySQL server on '' (61)")

This is my
file from my project :

'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'Etat_Civil',
'USER': 'root',
'PASSWORD': 'password',
'HOST': '',
'PORT': '3306',

On my Mac I installed
mysql connector/python

I don't work with a virtual environment because I just have one project in my laptop. So it's not necessary to isolate Python.

I think that's maybe a permission problem but I don't really know How configure that. I found some tutorials but I get problems each time.

Do you have some ideas ?

Thank you so much ;)

Answer Source

Firstly, you need to allow remote connections by editing my.cnf file and commenting the line that starts with bind-address as follows (You may also just change your machine ip address):

#bind-address                   =

Then restart mysql service:

sudo service mysql restart

Grant privileges to your user as follows:

mysql> CREATE USER 'root'@'172.30.10.%' IDENTIFIED BY 'password';
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'172.30.10.%'

To grant privileges only on Etat_Civil, you can try:

mysql> GRANT ALL PRIVILEGES ON Etat_Civil.* TO 'root'@'172.30.10.%'