MYSQL_OPT_PROTOCOL set improperly when port specified
MySQL database connector for Python programming
Brought to you by:
adustman
When a call to connect() does not contain a unix_socket (as when you are connecting to either a remote or a windows-based mysql server), the code leaves MYSQL_OPT_PROTOCOL set to the default, 0, which is for unix sockets, which causes the connection to fail with the error: 2002, Cannot connect to MySQL server on socket: ''
If only a port option is specified, the code should explicitly set the MYSQL_OPT_PROTOCOL option to tcp, or 1.
Without this, it will attempt to use protocol 0, and since there is no unix_socket option set, it will use whatever socket value is compiled in to the mysqlclient libs, and this is the only way you can ever connect, regardless of whether you pass a valid port option to connect().
patch to set MYSQL_OPT_PROTOCOL