本文介绍了如何修复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.
这篇关于如何修复InterfaceError:2003:无法连接到'127.0.0.1:3306:3306'上的MySQL服务器(11001 getaddrinfo失败)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!