Setting up mysql client on Cygwin

jdavidb on 2009-04-22T14:38:08

I'm running Windows MySQL server, but I'm doing an increasing amount of my development work from Cygwin (thankfully). Unfortunately, to get maximum benefit out of Cygwin I want to be doing my work from xterms, and the Windows MySQL client expects to run under the Windows console. I really don't want to launch Windows consoles with Cygwin bash just for MySQL (or anything else, for that matter), and I don't want to limit myself to CMD, so I wanted to use a Cygwin-native MySQL client.

To compile the client, I had to pass --without-server and --without-libedit to ./configure . The first option's meaning is obvious. The second seems confusingly-named to me: it directs MySQL to compile using libedit already installed on the system instead of compiling libedit from source bundled in its source tree. The option does not mean you won't get command-line history or anything. In fact, command-line history works beautifully and is much more preferable to what I get from the Windows MySQL client.

After installation, the client wants to connect through a local socket. I doubt that this can be made to work from Cygwin to Windows MySQL server, but I suppose it might be as simple as needing to direct the client to look for the socket somewhere besides /tmp/mysql.sock (C:\cygwin\tmp\mysql.sock) or making a symlink. My approach instead is to tell the client to connect with TCP:

mysql --protocol=tcp

This of course is inconvenient to type every time, so I put it in ~/.my.cnf . (I used strace on the failing mysql client to determine the potential locations for my.cnf were: /etc/my.cnf, /etc/mysql/my.cnf, /usr/local/etc/my.cnf, and $HOME/.my.cnf .) The my.cnf syntax is:

[client]
protocol=tcp

Googling revealed that it was also possible to force the client to connect with tcp by telling it to use 127.0.0.1 as the host. Mysteriously, this does not work when the host is specified as localhost.