#60 MYSQL_OPT_PROTOCOL set improperly when port specified

MySQLdb
open
Andy Dustman
MySQLdb (53)
5
2012-09-19
2009-02-05
Jesse Dailey
No

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().

Discussion

  • Jesse Dailey
    Jesse Dailey
    2009-02-05

    patch to set MYSQL_OPT_PROTOCOL