Bug #63544 Problem with keystroke handling from XTERM
Submitted: 2 Dec 2011 16:48 Modified: 27 Dec 2011 11:41
Reporter: Emanuele Tomasi Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:5.1.59 OS:Any
Assigned to: CPU Architecture:Any
Tags: alt, client, keys, xterm

[2 Dec 2011 16:48] Emanuele Tomasi
Description:
When I start a connection from Xterm with mysql command I can't use Alt+key movements (emacs mode for readline). In addiction, when I close mysql client it let my Xterm in trouble: I no longer can use the shortcut above.

I use Slackware64.

How to repeat:
In my Xterm session I do:
mysql

Suggested fix:
I can solve this problem if I set TERM variable to 'linux' instead 'xterm'. This alias work fine for me:
alias mysql='TERM=linux mysql'
[2 Dec 2011 18:11] Valeriy Kravchuk
If the problem is solved by setting other value for TERM, why do you think this is a problem in mysql client and not in xterm, for example? 

Can you use the same keystrokes in other client that uses readline, like bash shell, while in xterm?
[2 Dec 2011 18:25] Emanuele Tomasi
Hi Valeriy,
yes, before I run mysql client I can use readline keystrokes in bash shell within xterm.

Regards,
Emanuele
[19 Dec 2011 17:10] Sveta Smirnova
Thank you for the feedback.

Please send your readline configurtion file and output of command \s in MySQL command line client.
[19 Dec 2011 23:29] Emanuele Tomasi
inputrc for readline

Attachment: inputrc (application/octet-stream, text), 951 bytes.

[19 Dec 2011 23:30] Emanuele Tomasi
Output of '\s' command in mysql client

Attachment: command (application/octet-stream, text), 1.21 KiB.

[19 Dec 2011 23:31] Emanuele Tomasi
Hi Sveta,
I attached the files you requested.

Best regards,
Emanuele
[20 Dec 2011 12:09] Sveta Smirnova
Thank you for the feedback.

I can not repeat described behavior with current development sources. Please try with current version 5.1.60 available from dev.mysql.com/downloads and if problem still exists provide compile options you use to build MySQL (I saw "Source distribution" in the "\s" output, so I assume you build yourself).
[21 Dec 2011 16:18] Emanuele Tomasi
Sveta,
I don't think that is a compilation problem. I don't build mysql by myself, instead I use the package provided by Slackware. The build options are:
---
/configure \
  --prefix=/usr \
  --libdir=/usr/lib${LIBDIRSUFFIX} \
  --with-mysqld-user=mysql \
  --with-unix-socket-path=/var/run/mysql/mysql.sock \
  --localstatedir=/var/lib/mysql \
  --mandir=/usr/man \
  --infodir=/usr/info \
  --enable-assembler \
  --without-debug \
  --enable-thread-safe-client \
  --with-extra-charsets=complex \
  --with-ssl=/usr \
  --enable-largefile \
  --with-innodb \
  --with-readline \
  --build=$ARCH-slackware-linux
---

The problem seems be something about charset. I have LANG setted on 'it_IT@euro' (note that I don't use UTF8). When I run mysql client seems it use UTF8 charset because I see, e.g. for alt+f the symbol 'â' and for alt+b the symbol 'æ'. Again, when I quit from client, alt+backspace do nothing but after this I can go back beyond prompt. E.g.:
Normal promp:
=>
If I press alt+backspace all is the same, but after, if i press backspace:
=

I hope this help you to find the "bug",
Emanuele
[21 Dec 2011 16:41] Sveta Smirnova
Emanuele,

thank you for the feedback.

If you don't use UTF8, please, run SET NAMES latin1 and check if this solves the problem. I think collation latin1_general_ci would perfectly work for Italian.
[21 Dec 2011 18:02] Emanuele Tomasi
No Sveta,
SET NAMES doesn't resolve the problem. But, as I said, setting TERM variable to 'linux' is a good workaround, does this help you?

Emanuele
[26 Dec 2011 17:50] Sveta Smirnova
Thank you for the feedback.

I still can not repeat described behavior. Please try with our binaries and version 5.1.60 available from dev.mysql.com/downloads and inform us if problem still exits. You can use generic Linux binaries.
[26 Dec 2011 18:59] Emanuele Tomasi
Sveta, I didn't find the 5.1.60. I tried 5.1.59 found in this location:
http://downloads.mysql.com/archives.php?p=mysql-5.1
but the problem still exists. I report what I did:
---
#> cd /usr/local
#> ln -sf /tmp/mysql-5.1.59-linux-x86_64-glibc23/bin mysql
#> cd mysql/bin
#> ./mysqld_safe --datadir=/var/lib/mysql --pid-file=/var/run/mysql/mysql.pid --skip-networking
---
And then with normal user:
---
$> cd /usr/local/mysql/bin
$> ./mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.59 MySQL Community Server (GPL)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> \s
--------------
./mysql  Ver 14.14 Distrib 5.1.59, for unknown-linux-gnu (x86_64) using readline 5.1

Connection id:          1
Current database:
Current user:           spina@localhost
SSL:                    Not in use
Current pager:          stdout
Using outfile:          ''
Using delimiter:        ;
Server version:         5.1.59 MySQL Community Server (GPL)
Protocol version:       10
Connection:             Localhost via UNIX socket
Server characterset:    latin1
Db     characterset:    latin1
Client characterset:    latin1
Conn.  characterset:    latin1
UNIX socket:            /var/run/mysql/mysql.sock
Uptime:                 1 min 2 sec

Threads: 1  Questions: 4  Slow queries: 0  Opens: 17  Flush tables: 1  Open tables: 4  Queries per second avg: 0.64
--------------

mysql> useâ
---

As you can see I typed 'use' plus 'alt+b' and the terminal shows 'useâ'.

If you write the right location for the version 5.1.60 I'll try it too.

Best regards and merry (past) Xmas,
Emanuele
[27 Dec 2011 11:35] Emanuele Tomasi
Sveta, I resolved the problem. It's not a mysql bug but a mistake in readline configuration. I wrote an email to Thomas Dickey, the developer of xterm, and he linked me to this page:
http://invisible-island.net/ncurses/ncurses.faq.html#bash_meta_mode

For my PC, the correct configuration for readline within xterm is:
set convert-meta On
set input-meta Off
set output-meta Off

Best regards,
Emanuele
[27 Dec 2011 11:41] Emanuele Tomasi
I forgot to say that is the default readline configuration (readline(3)), but, strangely on my PC I had:
---
convert-meta is set to `off'
enable-meta-key is set to `on'
input-meta is set to `on'
meta-flag is set to `on'
output-meta is set to `on'
---

Emanuele