Django connection mysql, displays Can't connect to MySQL server on 'localhost'

problem description

python mysql is all installed successfully. The framework uses django, to connect to mysql with the error of
clipboard.png
all the time.
now mysql is running normally. If I delete the code in the database part of django, the program will run normally. Visit 127.0.0.1mysql 8080 in the browser

.

sources of topics and their own ideas

I checked the relevant information and showed that the database could not be connected because the database was not open, but mine is always open. What I understand is that the database connection is wrong, but the host and port of the mysql I configured are correct.

related codes

DATABASES = {
    "default": {
        "ENGINE": "django.db.backends.mysql",
        "NAME": "test",
        "USER": "root",
        "PASSWORD": "password",
        "HOST": "127.0.0.1",
        "PORT": "3307",
    },
}

does any god know what"s going on? How to solve it?

May.16,2021
The ip address of

database is not written, and 'HOST':' is changed to 'HOST':' 127.0.0.1'. If not, your local MySQL service should not be started, so you can test it at the terminal 'telnet 127.0.0.1 3306' . Welcome to adopt ~


seems to have encountered this problem. When you configure 'HOST':' 127.0.0.1', django will access the database through localhost instead of the ip address 127.0.0.1.
but your database is not configured with permissions for root users to access through the localhost domain name

mysql> use mysql; 
mysql> update user set host = 'localhost' where user = 'root';   -- localhost
mysql> update user set host = '%' where user = 'root';   -- 
mysql> select host, user from user; 
mysql> flush privileges;

or


if the local machine acts as both the server and the client, there is a good chance that the server is not enabled, so you can test it. On this machine, you can also run the mysql interface directly to see the specific situation

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b37ad5-2c0ac.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b37ad5-2c0ac.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?