Bug #70340 Connection timed out with valid settings
Submitted: 13 Sep 2013 18:07 Modified: 13 Jan 2014 8:35
Reporter: Normann Koldrack Email Updates:
Status: Not a Bug Impact on me:
None 
Category:Connector / Python Severity:S3 (Non-critical)
Version:1.1.1a1 OS:Any
Assigned to: Geert Vanderkelen CPU Architecture:Any
Tags: Connect failed, python 2

[13 Sep 2013 18:07] Normann Koldrack
Description:
its not possible to connect to a database using the same login data as for MySQLdb.

How to repeat:
Python 2.7.3 (default, Apr 10 2013, 06:20:15)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import mysql.connector
>>> cnx = mysql.connector.connect(user="test", password="test", host="localhost", database="test")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "mysql/connector/__init__.py", line 96, in Connect
    return MySQLConnection(*args, **kwargs)
  File "mysql/connector/connection.py", line 115, in __init__
    self.connect(**kwargs)
  File "mysql/connector/connection.py", line 364, in connect
    self._open_connection()
  File "mysql/connector/connection.py", line 327, in _open_connection
    self._socket.open_connection()
  File "mysql/connector/network.py", line 381, in open_connection
    errno=2003, values=(self.get_address(), _strioerror(err)))
mysql.connector.errors.InterfaceError: 2003: Can't connect to MySQL server on '127.0.0.1:3306' (110 Connection timed out)

with MySQLdb:

>>> cnx = MySQLdb.connect(host="localhost", user="test", passwd="test", db="test")
>>> cnx.close()
[18 Sep 2013 7:17] Geert Vanderkelen
Hello Normann,

1) Is the MySQL server configured with skip-networking? If it, is there any firewall active? I'm asking because if skip-networking is set, it would actually result in a 'connection refused', not time out.

2) Try using the unix_socket option when connecting using MySQL Connector/Python. When you use MySQLdb, it uses the MySQL Client libraries, and localhost is a special case. In the Connector, 'localhost' is really 127.0.0.1, and not socket file.

Cheers,
Geert
[26 Sep 2013 10:34] Normann Koldrack
1) skip-networking is not set

2) is working. Couldn't be localhost a special case too? I think this could be a pittfall for many users.

Thanks for your support.
[13 Jan 2014 8:35] Geert Vanderkelen
Hi Normann,

I have decided from the start of Connector/Python that 'localhost' will not be a 'special case' and this will not change. It one needs UNIX socket, explicit mentioning of unix_socket connection argument is the way to go.

Cheers,
Geert