In this article, we will share another problem we encountered during the development process: Python3 analyzes pedestrian checks and mysql denies access after the program is run directly.

Program run directly to connect the mysql database error: “pymysql. Err. OperationalError: (2003, “Cant connect to mysql server on ‘localhost’ ([WinError 10061])”)

Let’s start with a piece of code:

This code is the code to connect to the mysql database. The mysql server is running, and HeidiSQL is also available for connection.

We tried to fix this by changing the dbhost value to ‘127.0.0.1’ in the code, but the change still didn’t work. At this point, you can only try modifying the hosts file in a computer file. Add a line: 127.0.0.1 localhost. The modification is complete, restart the computer, run again, still no response. Start CMD, ping localhost:

You can see the logo [::1] appearing in the image above. Win10 解 决 localhost解 决 ipv6:127.0.0.1 localhost解 决 ipv6:127.0.0.1 localhost解 决 ipv6:127.0.0.1 localhost解 决 ipv6:127.0.0.1 localhost解 决 ipv6:127.0.0.1 localhost解 决 ipv6:127.0.0.1 localhost解 决 ipv6:127.0.0.1

Open the registry and find the key HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\ tcPIp6 \Parameters; Add an item of type DWORD with the name DisabledComponents (unnecessary if it exists); Then change the value inside to 20, which is set to hexadecimal.

Save the registry and restart the computer to show that the connection can be reconnected to mysql. The problem is resolved.