Starting Nmap 7.92 ( https://nmap.org ) at 2022-01-07 11:55 CET
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000082s latency).
PORT STATE SERVICE
3306/tcp closed mysql
Nmap done: 1 IP address (1 host up) scanned in 0.08 seconds
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on '123@localhost' ([Errno -2] Name or service not known)")
如果您通过 WSL (Linux 的 Windows 子系统)运行 Ubuntu并希望连接到主机上的 MySQL 实例,则需要使用主机的 IPv4地址,例如 192.X.X.X,而不是 127.0.0.1或 localhost。
$ mysql -u <user> -h 127.0.0.1 -p -P 3306
ERROR 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111)
$ mysql -u <user> -h 192.X.X.X -p -P 3306
Welcome to the MySQL monitor...Server version: 8.0.26 MySQL Community Server - GPL
Copyright (c) 2000, 2022, Oracle and/or its affiliates.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
mysql+mysqlconnector://<user>:<password>@localhost:3306/<database>
(mysql.connector.errors.DatabaseError) 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (111)
或者
mysql+mysqlconnector://<user>:<password>@127.0.0.1:3306/<database>
(mysql.connector.errors.DatabaseError) 2003 (HY000): Can't connect to MySQL server on '127.0.0.1:3306' (111)