[Django]-Django unable to connect to MySQL server

2👍

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 127.0.0.1by your machine ip address):

#bind-address                   = 127.0.0.1

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.%'

2👍

Looks like MySQL is configured to listen only on localhost.

You can test this by running telnet 172.30.10.59 3306 from your client machine.

Please try to follow Configuration step described here:

Edit the /etc/mysql/my.cnf file to configure MySQL to listen for connections from network hosts, change the bind-address directive to the server’s IP address. For example Replace 172.30.10.59 with the appropriate address. If there are no such entry – uncomment it or create new line.

 bind-address = 172.30.10.59

Then restart mysqld with this command:

 sudo service mysql restart

Then test with telnet or by running your application once again. Also netstat would have second entry for mysqld.

0👍

The problem may be ‘HOST’: ‘172.30.10.58’
You can change IP address to your hostname.

  1. If you are using Ubuntu, check the name in
    sudo vi /etc/hostname and sudo vi /etc/hosts
  2. If you are using docker, go to docker

    docker exec -it CONTAINER_ID bash

    sudo vi /etc/hostname and sudo vi /etc/hosts

Hope this help !

👤UzanR

Leave a comment