Bug #16557 mysql cmd-line client does not rename .mysql_history.TMP to .mysql_history
Submitted: 17 Jan 2006 3:30 Modified: 27 Feb 2006 20:34
Reporter: Andrew Donkin Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.18 OS:Linux (Linux x86)
Assigned to: Magnus Blåudd CPU Architecture:Any

[17 Jan 2006 3:30] Andrew Donkin
Description:
When built from source without --without-readline, the 5.0.18 mysql command-line client saves its readline history in ~/.mysql_history.TMP but does not rename it to ~/.mysql_history .  This means that no history is saved between sessions.  This only happens when using the built-in libedit.a instead of libreadline.a.

cmd-line-utils/libedit/history.c:history_save() returns the number of history items saved.  That is passed back up through cmd-line-utils/libedit/readline.c:write_history()  which client/mysql.cc:mysql_end() interprets as failure, because it is non-zero.

How to repeat:
  ./configure --with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static \
  --disable-shared  --enable-assembler

Suggested fix:
--- cmd-line-utils/libedit/readline.c~  2005-12-22 08:39:24.000000000 +1300
+++ cmd-line-utils/libedit/readline.c   2006-01-17 16:09:19.000000000 +1300
@@ -1123,7 +1123,7 @@
 
        if (h == NULL || e == NULL)
                rl_initialize();
-       return (history(h, &ev, H_SAVE, filename));
+       return (history(h, &ev, H_SAVE, filename) == -1);
 }

Or use the system readline() by passing --without-readline to configure.
[13 Feb 2006 13:03] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/2515
[21 Feb 2006 7:59] Magnus Blåudd
this is in the netbsd upstream source now. 

http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libedit/readline.c.diff?r1=1.59&r2=1.60
[21 Feb 2006 8:06] Magnus Blåudd
this is in the netbsd upstream source now. 

http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libedit/readline.c.diff?r1=1.59&r2=1.60
[24 Feb 2006 8:23] Magnus Blåudd
Pushed a fix to 5.0.19 and 5.1.8 that makes libedit functions 'read_history' and 'write_history' return the same error code as their readline counterparts.

Approved by Jim.
[27 Feb 2006 20:34] Mike Hillyer
Documented in the 5.0.19 and 5.1.8 changelogs:

      <listitem>
        <para>
          Clients compiled from source with the
          <option>--without-readline</option> did not save command
          history from session to session. (Bug #16557)
        </para>
      </listitem>