I often use the mysql command-line client on an Ubuntu box. It works fine, except that the key bindings are wrong. Specifically, pressing "Home", "End", or "Delete" makes it output a ~ (tilde) character, and beep.

I've determined that Home/End can be done by pressing Control+A and Control+E respectively, as on the Mac terminal. I'm on a Windows box, using PuTTY to talk to Ubuntu, but the home/end/delete keys work fine on the regular command line. I'm pretty sure it's an issue specific to the mysql client.

I checked the man file but didn't find anything useful. Is there any way to bind the Home/End/Delete keys to their actual functions? Maybe a config file in my home directory or something?

Every time I move back a few spaces to edit a query and press delete, I just wind up having to go forward again so I can use the Backspace key to delete not only the incorrect query but also the ~ that the delete key puts in.

It's driving me slowly but surely to madness. Madness, I tell you, MADNESS!

  • Not really suitable for ServerFault (more a SuperUser or Unix & Linux question) but I'll answer anyway. – Andrew Apr 5 '11 at 2:51
  • Ah. I wasn't sure where to put this, but ServerFault seemed reasonable since a pretty high proportion of server admins are familiar with the software involved. Thanks for answering anyway; in future I'll save ServerFault for truly server-ish things like problems configuring a load balancer or whatever. – Will Martin Apr 5 '11 at 5:23

Okay, I noticed that my home server did not have the problem, and comparing the work and home servers let me finally nail it down.

It's a bug Ubuntu introduced in version 9.10, which is what my work server is running. Specifically, the version of /usr/bin/mysql in Ubuntu 9.10 uses the EditLine wrapper instead of the readline wrapper:

wmartin@work:~$ mysql --version && md5sum /usr/bin/mysql && lsb_release -a

mysql  Ver 14.14 Distrib 5.1.37, for debian-linux-gnu (i486) using EditLine wrapper

e23604381e64ac805fdbb8b334ce4d17  /usr/bin/mysql

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 9.10
Release:        9.10
Codename:       karmic

Compare to the more recent release on my home server:

wmartin@home:~$ mysql --version && md5sum /usr/bin/mysql && lsb_release -a

mysql  Ver 14.14 Distrib 5.1.41, for debian-linux-gnu (i486) using readline 6.1

4274c43798239142576e77c022d35bd1  /usr/bin/mysql

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 10.04.2 LTS
Release:        10.04
Codename:       lucid

The 10.04 (and presumably later) versions work just fine -- mysql honors the home/end/delete keys using Putty's default settings.

So the solution is either to upgrade the server to 10.04 or later, or to use the command line utility rlwrap to wrap the mysql client in a readline environment, as described in the blog post restoring readline capabilities of Ubuntu's 9.10 (Karmic Koala) MySQL Client.

Sadly, the rlwrap approach has the nasty side effect of making your password visible when you type it in instead of suppressing its output. So I think I'll take the upgrade route.

  • Well done for tracking it down - using the Ubuntu LTS releases is much preferred to "whatever is the latest release" for servers. – Andrew Apr 6 '11 at 2:16

I'd say the problem is your PuTTY settings - in the connection window, under "Terminal", "Keyboard" - change options for "The Home and End keys" to rxvt. Not perfect (End won't work still) but you'll get Home and Delete.

IMO the real solution is to use a proper terminal & proper SSH; Console2 is reasonably good for a terminal, and MSYS or Cygwin can give you SSH (msysgit has it included).


Sounds like you've found the bug in MySQL CLI.

  • Actually, I take it back. That didn't fix it. In BASH, I get Home and Delete but not End (which is worse -- all three worked in BASH before). In the MySQL client, Home works, but Delete and End still do tildes. Doing more investigation ... – Will Martin Apr 5 '11 at 21:12
  • @Will fair enough. – Andrew Apr 6 '11 at 2:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.