jermina jermina - 11 months ago 82
Apache Configuration Question

error when using mysql.connector for python to connect database

I am newbie to python ,started with implementing small programs ,now trying with connecting database .I installed python 3.4 and mysql.connector 2.0.4 .
Below given code is what i used to connnect the database

import sys
import mysql.connector
print("Content-Type: text/html;charset=utf-8")
conn = mysql.connector.connect(host='localhost:8051',

if conn.is_connected():
print('Connected to MySQL database')

But i am getting error as given below . not getting why this error are occurring ,because of setup environment is wrong or of some other reason
Please suggest

Traceback (most recent call last):
File "C:\Python34\lib\site-packages\mysql\connector\", line 448, in open_connection
File "C:\Python34\lib\", line 533, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
socket.gaierror: [Errno 11004] getaddrinfo failed

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<pyshell#8>", line 2, in <module>
File "C:\Python34\lib\site-packages\mysql\connector\", line 179, in connect
return MySQLConnection(*args, **kwargs)
File "C:\Python34\lib\site-packages\mysql\connector\", line 95, in __init__
File "C:\Python34\lib\site-packages\mysql\connector\", line 719, in connect
File "C:\Python34\lib\site-packages\mysql\connector\", line 209, in _open_connection
File "C:\Python34\lib\site-packages\mysql\connector\", line 464, in open_connection
errno=2003, values=(self.get_address(), _strioerror(err)))
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on 'localhost:8051:3306' (11004 getaddrinfo failed)

Answer Source

The error message is quite clear:

 Can't connect to MySQL server on 'localhost:8051:3306'

See the double port definition?


should most likey be

host='localhost', port='8051'