How to fix InterfaceError: 2003: Can't connect to MySQL server on '127.0.0.1:3306:3306' (11001 getaddrinfo failed)
Question:
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)
Answers:
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"
)
You don’t need to though – 3306 is the default MySQL port and it would appear that’s what you are using.
import mysql.connector
# establishing the connection
conn = mysql.connector.connect(
user='root', host='localhost', port=3306, database='test')
cursor = conn.cursor()
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)
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"
)
You don’t need to though – 3306 is the default MySQL port and it would appear that’s what you are using.
import mysql.connector
# establishing the connection
conn = mysql.connector.connect(
user='root', host='localhost', port=3306, database='test')
cursor = conn.cursor()