Bug #95287 mysql client ignores ~/.editrc. bind "^W" ed-delete-prev-word doesn't work
Submitted: 8 May 2019 7:47 Modified: 4 Oct 2019 11:50
Reporter: Ildar Amankulov Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Command-line Clients Severity:S3 (Non-critical)
Version:8.0.17 OS:Linux (Linux aim-server.crtdev.local 5.0.5-arch1-1-ARCH #1 SMP PREEMPT Wed Mar 27 17:53:10 UTC 2019 x86_64 )
Assigned to: CPU Architecture:x86 (x86_64)

[8 May 2019 7:47] Ildar Amankulov
Description:
When I type CTRL+W in mysql console client it removes the whole query.
================================================================

cat ~/.editrc
bind "^W" ed-delete-prev-word
bind "^U" vi-kill-line-prev
#bind "OF" ed-move-to-end # some problem with shift+insert
#bind "OH" ed-move-to-beg
bind "[C" ed-next-char
bind "[D" ed-prev-char
================================================================

ldd /usr/bin/mysql
	linux-vdso.so.1 (0x00007fff34de3000)
	libjemalloc.so.2 => /usr/lib/libjemalloc.so.2 (0x00007f9e017d4000)
	libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f9e017b3000)
	libedit.so.0 => /usr/lib/libedit.so.0 (0x00007f9e01779000)
	libz.so.1 => /usr/lib/libz.so.1 (0x00007f9e01562000)
	libssl.so.1.1 => /usr/lib/libssl.so.1.1 (0x00007f9e014d2000)
	libcrypto.so.1.1 => /usr/lib/libcrypto.so.1.1 (0x00007f9e011fe000)
	libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f9e011f7000)
	libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f9e01067000)
	libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f9e0104d000)
	libc.so.6 => /usr/lib/libc.so.6 (0x00007f9e00e89000)
	/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f9e021f4000)
	libncursesw.so.6 => /usr/lib/libncursesw.so.6 (0x00007f9e00e1a000)
	libm.so.6 => /usr/lib/libm.so.6 (0x00007f9e00c95000)

================================================================
libedit Version         : 20181209_3.1-1

================================================================
BUILD instructions
pkgname=('mysql' 'libmysqlclient' 'mysql-clients')
pkgbase=mysql
pkgver=8.0.15
pkgrel=1
pkgdesc="Fast SQL database server, community edition"
arch=('x86_64')
makedepends=('openssl' 'zlib' 'cmake' 'systemd-tools' 'libaio' 'jemalloc'
             'rpcsvc-proto' 'libtirpc' 'icu' 'libedit' 'libevent' 're2'
             'rapidjson' 'protobuf')
license=('GPL')
url="https://www.mysql.com/products/community/"
options=('!libtool' '!ccache') # Sorry but actually ccache is not supported
source=("https://cdn.mysql.com/Downloads/MySQL-8.0/${pkgbase}-boost-${pkgver}.tar.gz"
        "mysqld-post.sh"
        "mysqld-tmpfile.conf"
        "mysqld.service"
        "my-default.cnf"
        "mysql-ld.so.conf")
sha256sums=('95dbdb54c3967feefb255b96458b089a601e4de238bcc1f328b066018ee47db0'
            '368f9fd2454d80eb32abb8f29f703d1cf9553353fb9e1ae4529c4b851cb8c5dd'
            '2af318c52ae0fe5428e8a9245d1b0fc3bc5ce153842d1563329ceb1edfa83ddd'
            '50212165bdb09855b97b15a917464ba34f82edf30a0c43f9a0c93a27071df556'
            '3cc3ba4149fb2f9e823601b9a414ff5b28a2a52f20bc68c74cc0505cf2d1832d'
            'e1c23fa0971a13d998f2790379b68c475438d05b6d6f2691b99051dbf497567f')

build() {
  rm -rf build
  mkdir build
  cd build

  cmake "../${pkgbase}-${pkgver}" \
    -DCMAKE_AR=/usr/bin/gcc-ar \
    -DCMAKE_RANLIB=/usr/bin/gcc-ranlib \
    -DBUILD_CONFIG=mysql_release \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DSYSCONFDIR=/etc/mysql \
    -DMYSQL_DATADIR=/var/lib/mysql \
    -DMYSQL_UNIX_ADDR=/run/mysqld/mysqld.sock \
    -DENABLED_LOCAL_INFILE=ON \
    -DINSTALL_INFODIR=share/mysql/docs \
    -DINSTALL_MANDIR=share/man \
    -DINSTALL_PLUGINDIR=lib/mysql/plugin \
    -DINSTALL_SCRIPTDIR=bin \
    -DINSTALL_INCLUDEDIR=include/mysql \
    -DINSTALL_DOCREADMEDIR=share/mysql \
    -DINSTALL_SUPPORTFILESDIR=share/mysql \
    -DINSTALL_MYSQLSHAREDIR=share/mysql \
    -DINSTALL_DOCDIR=share/mysql/docs \
    -DINSTALL_SHAREDIR=share/mysql \
    -DWITH_SYSTEM_LIBS=ON \
    -DWITH_LIBWRAP=OFF \
    -DCMAKE_EXE_LINKER_FLAGS='-ljemalloc' \
    -DWITHOUT_EXAMPLE_STORAGE_ENGINE=ON \
    -DWITHOUT_FEDERATED_STORAGE_ENGINE=ON \
    -DCMAKE_C_FLAGS="${CFLAGS}" \
    -DCMAKE_C_LINK_FLAGS="${LDFLAGS}" \
    -DCMAKE_CXX_FLAGS="${CXXFLAGS}" \
    -DCMAKE_CXX_LINK_FLAGS="${LDFLAGS}" \
    -DWITH_BOOST="../${pkgname}-${pkgver}/boost"
  make
}

package_libmysqlclient(){
  pkgdesc="MySQL client libraries"
  depends=('libsasl' 'zlib')
  conflicts=('libmariadbclient' 'mariadb-libs')
  provides=("libmariadbclient=${pkgver}" "libmysqlclient=${pkgver}" "mariadb-libs=${pkgver}")

  cd build
  for dir in include libmysql libservices
  do
    make -C "${dir}" DESTDIR="${pkgdir}" install
  done

  install -m 755 -d "${pkgdir}/usr/bin"
  install -m 755 scripts/mysql_config "${pkgdir}/usr/bin/"
  install -m 755 -d "${pkgdir}/usr/share/man/man1"
  for man in mysql_config
  do
    install -m 644 "${srcdir}/${pkgbase}-${pkgver}/man/${man}.1" "${pkgdir}/usr/share/man/man1/${man}.1"
  done
}

package_mysql-clients(){
  pkgdesc="MySQL client tools"
  depends=('libmysqlclient' 'zlib' 'openssl' 'jemalloc' 'libedit' 'lz4')
  conflicts=('mariadb-clients')
  provides=("mariadb-clients=${pkgver}" "mysql-clients=${pkgver}")

  cd build
  make -C "client" DESTDIR="${pkgdir}" install

  # install man pages
  install -d "${pkgdir}/usr/share/man/man1"
  for man in mysql mysqladmin mysqlcheck mysqldump mysqlimport mysqlshow mysqlslap
  do
    install -m644 "${srcdir}/${pkgbase}-${pkgver}/man/${man}.1" "${pkgdir}/usr/share/man/man1/${man}.1"
  done

  # provided by mysql
  rm "${pkgdir}/usr/bin/mysql_upgrade"
  rm "${pkgdir}/usr/bin/mysql_config_editor"
  rm "${pkgdir}/usr/bin/mysqlbinlog"
  rm "${pkgdir}/usr/bin/mysql_secure_installation"
  rm "${pkgdir}/usr/bin/mysql_ssl_rsa_setup"
  rm "${pkgdir}/usr/bin/mysqltest"
}

package_mysql(){
  pkgdesc="Fast SQL database server, community edition"
  backup=('etc/mysql/my.cnf')
  install="${pkgbase}.install"
  depends=('mysql-clients' 'libsasl' 'zlib' 'jemalloc' 'libaio' 'libtirpc' 'icu'
           'lz4' 'libevent' 'protobuf')
  conflicts=('mariadb')
  provides=("mariadb=${pkgver}" "mysql=${pkgver}")
  options=('emptydirs')

  cd build
  make DESTDIR="${pkgdir}" install

  install -m 644 -D "${srcdir}/my-default.cnf" "${pkgdir}/etc/mysql/my.cnf"
  install -m 755 -D "${srcdir}/mysqld-post.sh" "${pkgdir}/usr/bin/mysqld-post"
  install -m 644 -D "${srcdir}/mysqld-tmpfile.conf" "${pkgdir}/usr/lib/tmpfiles.d/mysqld.conf"
  install -m 755 -d "${pkgdir}/usr/lib/systemd/system"
  install -m 644 -D "${srcdir}/mysqld.service" "${pkgdir}/usr/lib/systemd/system/"
  install -m 755 -d "${pkgdir}/etc/ld.so.conf.d"
  install -m 644 -D "${srcdir}/mysql-ld.so.conf" "${pkgdir}/etc/ld.so.conf.d/${pkgname}.conf"

  # provided by libmysqlclient
  rm "${pkgdir}/usr/bin/mysql_config"
  rm "${pkgdir}/usr/lib/libmysqlclient.so"
  rm "${pkgdir}/usr/lib/libmysqlclient.so.21"
  rm "${pkgdir}/usr/lib/libmysqlclient.so.21.0.15"
  rm "${pkgdir}/usr/lib/libmysqlservices.a"
  rm "${pkgdir}/usr/lib/mysql/plugin/authentication_ldap_sasl_client.so"
  rm -r "${pkgdir}/usr/include/"
  rm "${pkgdir}/usr/share/man/man1/mysql_config.1"

  # provided by mysql-clients
  rm "${pkgdir}/usr/bin/mysql"
  rm "${pkgdir}/usr/bin/mysqladmin"
  rm "${pkgdir}/usr/bin/mysqlcheck"
  rm "${pkgdir}/usr/bin/mysqldump"
  rm "${pkgdir}/usr/bin/mysqlimport"
  rm "${pkgdir}/usr/bin/mysqlpump"
  rm "${pkgdir}/usr/bin/mysqlshow"
  rm "${pkgdir}/usr/bin/mysqlslap"
  rm "${pkgdir}/usr/share/man/man1/mysql.1"
  rm "${pkgdir}/usr/share/man/man1/mysqladmin.1"
  rm "${pkgdir}/usr/share/man/man1/mysqlcheck.1"
  rm "${pkgdir}/usr/share/man/man1/mysqldump.1"
  rm "${pkgdir}/usr/share/man/man1/mysqlimport.1"
  rm "${pkgdir}/usr/share/man/man1/mysqlshow.1"
  rm "${pkgdir}/usr/share/man/man1/mysqlslap.1"

  # not needed
  rm -r "${pkgdir}/usr/mysql-test"
  rmdir "${pkgdir}/usr/run"

  # Move somewhere else
  mv "${pkgdir}/usr/LICENSE.router" "${pkgdir}/usr/share/mysql/docs"
  mv "${pkgdir}/usr/README.router" "${pkgdir}/usr/share/mysql/docs"

  # Fix permissions
  chmod 755 "${pkgdir}/usr"
}

How to repeat:
1)install arch linux via
-docker https://wiki.archlinux.org/index.php/Docker#Arch_Linux
or 
-vagrant image https://www.archlinux.org/download/
or
-VirtualBox/VMware https://www.osboxes.org/arch-linux/

2)install the package 
https://aur.archlinux.org/packages/mysql-clients/

3)run mysql client from console
[8 May 2019 7:48] Ildar Amankulov
BUILD instructions

Attachment: PKGBUILD.txt (text/plain), 6.19 KiB.

[8 May 2019 14:18] MySQL Verification Team
HI,

Actually your .editrc worked just fine for me.

I only removed your quotes ........
[13 May 2019 8:04] Ildar Amankulov
Hello, 

It is definitely a bug.

I have just installed arch linux64 + mysql from scratch.
The bug is reproduced.

You can try it in the configured environment.

For that:
1)Install http://virtualbox.org/
2)Create a Virtual guest arch linux 64 with the attached image (you can just copy the 64bit folder to the folder where your other VMs are located)

https://drive.google.com/drive/folders/1Qf2XQK26zHxwv35jeNVMKRI8v6IRvG_N?usp=sharing

3)Run the guest and login
4)Run mysql -uroot -p1 and try any query

USERS
root / 1
aim / 1

PS
according to https://dev.mysql.com/doc/refman/8.0/en/mysql-tips.html#mysql-input-editing
quotes should be there
[13 May 2019 13:58] MySQL Verification Team
Hi,

It turns out that we are not maintaining this library. I will double check that and will confirm this to you in my next comment.
[14 May 2019 12:44] MySQL Verification Team
Hi,

We have investigating the issue further. 

Libedit that we use for our command line interface is the one that is shipped with our source.

We debugged and found out that proper .editrc is read with our libedit library. We also found that the default key binding for the Ctrl-W is exactly ed-delete-prev-word.

Hence, use our bundled libedit as we do not support any other version.
[14 May 2019 13:25] Ildar Amankulov
Hello,

Thank you for your reply.

Could you suggest which version of libedit is used by mysql 8.0.15 ?

I suppose the history is here
https://thrysoee.dk/editline/
[14 May 2019 14:10] MySQL Verification Team
It is the one that it distributed with our source package.
[2 Aug 2019 11:59] Ildar Amankulov
Upgrade to 8.0.16 didn't help me.

The possible reason is  
https://github.com/knz/go-libedit/issues/3#ref-commit-84b7963

as this instruction doesn't work for me 
           To see the current set of key bindings, temporarily put a line that says only bind at the end of .editrc. mysql will show the bindings when it starts.
https://dev.mysql.com/doc/refman/8.0/en/mysql-tips.html#mysql-input-editing
[2 Aug 2019 17:58] MySQL Verification Team
Hi,

I just tested it with 8.0.16 and ^W worked just fine for me. I used libedit that comes with our source package and the same works with our binary packages.
[3 Oct 2019 10:16] Terje Røsten
Hi! 

Thanks for your report!

Your build is using cmake option:

 -DWITH_SYSTEM_LIBS=ON

which means libedit (and many other libs will be taken from build platform).

You see this from ldd too:

$ldd /usr/bin/mysql
	libedit.so.0 => /usr/lib/libedit.so.0 (0x00007f9e01779000)

libedit as shipped in MySQL server sources will not be used at all.

The code which does loading of ~/.editrc is located inside /usr/lib/libedit.so.0

Hence, the problem you see is due to something wrong in libedit.so.0 on your platform,
it's nothing MySQL can do to fix that.

If you build without the -DWITH_SYSTEM_LIBS=ON flag libedit from MySQL sources will be used and ~/.editrc will be loaded.
[3 Oct 2019 12:03] MySQL Verification Team
Terje,

Thanks a lot.

Your description is more verbose then mine, but it amounts to the same conclusions.

Thanks again.
[4 Oct 2019 11:50] Ildar Amankulov
Hello,

Thank you very much,
using the flag
 -DWITH_SYSTEM_LIBS=OFF
fixed the issue.

I have shared the idea here
https://aur.archlinux.org/pkgbase/mysql/#comment-710405

PS 
Currently, it looks like

ldd /usr/bin/mysql
	linux-vdso.so.1 (0x00007fffa1986000)
	libjemalloc.so.2 => /usr/lib/libjemalloc.so.2 (0x00007f333d29f000)
	libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f333d27e000)
	libssl.so.1.1 => /usr/lib/libssl.so.1.1 (0x00007f333d1ee000)
	libcrypto.so.1.1 => /usr/lib/libcrypto.so.1.1 (0x00007f333cf1d000)
	libdl.so.2 => /usr/lib/libdl.so.2 (0x00007f333cf18000)
	libncursesw.so.6 => /usr/lib/libncursesw.so.6 (0x00007f333cea9000)
	libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f333ccbf000)
	libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f333cca5000)
	libc.so.6 => /usr/lib/libc.so.6 (0x00007f333cae2000)
	/lib64/ld-linux-x86-64.so.2 => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f333dc0e000)
	libm.so.6 => /usr/lib/libm.so.6 (0x00007f333c99c000)