如何修复InterfaceError:2003:无法连接到'127.0.0.1:3306:3306'上的MySQL服务器(11001 getaddrinfo失败)

如何修复InterfaceError:2003:无法连接到'127.0.0.1:3306:3306'上的MySQL服务器(11001 getaddrinfo失败)

问题描述:

我的MySQL连接成功,但遇到此接口错误

my MySQL connection is successful but ran into this interface errror

import mysql.connector

db=mysql.connector.connect(
    host="127.0.0.1:3306",
    user="root",
    passwd="teja",
    database="test"
)

InterfaceError: 2003: Can't connect to MySQL server on '127.0.0.1:3306:3306' (11001 getaddrinfo failed)

将:3306"从主机"行中删除-mysql连接器本身正在添加导致无效地址的端口.

Take the ":3306" out of the "host" line - mysql connector is adding the port in itself leading to an invalid address.

如果需要 指定端口,以供将来参考,则可以仅指定一个单独的参数,如下所示:

For future reference if you do need to specify a port then you can just specify a separate parameter like so:

import mysql.connector

db=mysql.connector.connect(
   host="127.0.0.1",
   port="3306",
   user="root",
   passwd="teja",
   database="test"
)

您不需要-3306是默认的MySQL端口,它似乎就是您正在使用的端口.

You don't need to though - 3306 is the default MySQL port and it would appear that's what you are using.