Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Interface error: 2003' when connecting to database

I'm trying to use MySQL Connection/Python to connect to my database.

Here's the output I'm getting:

Traceback (most recent call last):
  File "bh2000.py", line 33, in <module>
    cnx = mysql.connector.connect(**config)
  File "/Library/Python/2.7/site-packages/mysql/connector/__init__.py", line 155, in connect
    return MySQLConnection(*args, **kwargs)
  File "/Library/Python/2.7/site-packages/mysql/connector/connection.py", line 123, in __init__
    self.connect(**kwargs)
  File "/Library/Python/2.7/site-packages/mysql/connector/connection.py", line 430, in connect
    self._open_connection()
  File "/Library/Python/2.7/site-packages/mysql/connector/connection.py", line 393, in _open_connection
    self._socket.open_connection()
  File "/Library/Python/2.7/site-packages/mysql/connector/network.py", line 375, in open_connection
    errno=2003, values=(self.get_address(), _strioerror(err)))
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'host xxx.db.1and1.com:3306' (8 nodename nor servname provided, or not known)

Here's the code I'm using:

import mysql.connector

cnx = mysql.connector.connect(user='xxx', password='xxx',
                              host='xxx.db.1and1.com',
                              database='xxx')
cnx.close()

Where am I going wrong?

like image 592
Sebastian Avatar asked Nov 10 '22 06:11

Sebastian


1 Answers

  • Did you specify the correct port?
  • Is your MySQL server running?
  • Is a firewall blocking access?
  • Try removing anonymous user account from your MySQL server?

Default port if not specified is 3306. Otherwise there is nothing wrong with your code. The problem is with your MySQL server or the connection is being blocked by your firewall or the server firewall. Make sure port 3306 is open and not blocked.

db = mysql.connector.connect(user='xxx', password='xxx', host='xxx.db.1and1.com', port=3306)
like image 87
panofish Avatar answered Nov 14 '22 21:11

panofish