3

Normally, autocompletion works fine in mysql command-line client (mysql-client-5.5). I have a table called booking. When I type the letter b and pres TAB the name of my table gets autocompleted:

SELECT * FROM b<TAB>

However, when I use rlwrap (alias mysql='/usr/bin/rlwrap -s 99999 -a -pRED /usr/bin/mysql'), autocompletion stops working.

It looks as if rlwrap is interfering with the autocompletion feature.

I am using Debian Wheezy.

UPDATE 1:

When I start my command with strace, ie:

strace /usr/bin/rlwrap -s 99999 -a -pRED /usr/bin/mysql --auto-rehash

I see following error

access("/usr/share/rlwrap/completions/mysql", R_OK) = -1 ENOENT (No such file or directory)

could it be, that rlwrap needs some file with mysql completions?

UPDATE 2

OK, I have created the file /usr/share/rlwrap/completions/mysql and put 3 sample lines there:

select
from
where

Now when I start mysql and type sele<TAB>, the tab actually completes the word select. That is progress, but that does not solve the whole problem. I mainly need autocompletion to help me complete obscure table names which I don't (want to) remember. But I cannot edit the autocomplete file every time I change/add/rename a table.

Is it not possible to tell rlwrap to use the same autocomplete file as mysql does? (I presume mysql must use some such file)

UPDATE 3:

following are the other errors from strace

access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
stat("/home/martin/.terminfo", 0x7fff27ee6a70) = -1 ENOENT (No such file or directory)
access("/etc/terminfo/x/xterm-256color", R_OK) = -1 ENOENT (No such file or directory)
access("/home/martin/.mysql_completions", R_OK) = -1 ENOENT (No such file or directory)
access("/usr/share/rlwrap/completions/mysql", R_OK) = -1 ENOENT (No such file or directory)
connect(4, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
connect(4, {sa_family=AF_FILE, path="/var/run/nscd/socket"}, 110) = -1 ENOENT (No such file or directory)
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
access("/etc/ld.so.nohwcap", F_OK)      = -1 ENOENT (No such file or directory)
stat("/home/martin/.inputrc", 0x7fff27ee7710) = -1 ENOENT (No such file or directory)
7
  • Why are you using rlwrap? mysql already used readline.
    – jordanm
    Oct 24, 2013 at 17:51
  • Not my mysql (I am using Debian Wheezy) Oct 24, 2013 at 17:56
  • 1
    A long shot and not my field, but you may find value in the idea of using a dictionary file for auto-completion, like this or here and that last link goes to this which contains already made dictionary files for different setups. Then you would use rlwrap -if dictfile sqlplus whatever -i to ignore case and -f to use the file dictfile.
    – user44370
    Jan 7, 2014 at 20:01
  • 1
    That's the first good lead we've had! I believe that's suppose to be a directory too, probably w/ some config files for rlwrap or mysql. toadworld.com/platforms/oracle/b/weblog/archive/2013/07/06/…
    – slm
    Jan 12, 2014 at 20:30
  • @slm - please see my update again Jan 12, 2014 at 20:59

3 Answers 3

2
+50

This will enable completion on plain mysql server:

mysql --auto-rehash

For rlwrap, check if you have RLWRAP_HOME set. See here for more info. The page also reports possible race conditions if your system is too busy.

2

Edit my.cnf:

[mysql]
auto-rehash

If that doesn't work, add it to debian.cnf instead.

Even you can do it:

mysql> \#
2
  • neither has any effect - auto-completion still does not work Jan 7, 2014 at 15:23
  • It sounds like you have another problem; it should work with the above change. Jan 11, 2014 at 7:13
0

I found this bit on a FreeBSD forum but it should work for you in your case as well. The forum thread was titled: Why no autocomplete in mysql with bash?.

The solutions mentioned in that thread are as follows.

Option #1 - via mysql client

$ mysql --auto-rehash -p

This is directly out of the mysql man page.

--auto-rehash

Enable automatic rehashing. This option is on by default, which enables 
database, table, and column name completion. Use --disable-auto-rehash to 
disable rehashing. That causes mysql to start faster, but you must issue the 
rehash command if you want to use name completion.

To complete a name, enter the first part and press Tab. If the name is 
unambiguous, mysql completes it. Otherwise, you can press Tab again to see 
the possible names that begin with what you have typed so far. Completion 
does not occur if there is no default database.

Option #2 - via the server

You can also fix this on the server end by commenting out that same feature line in the server's /etc/my.cnf file. It depends on where your my.cnf file came from. MySQL provides several out of the box sample .cnf files.

Example

This is on my CentOS system buy your Debian system likely has these as well.

$ rpm -ql mysql-server |grep cnf 
/usr/share/doc/mysql-server-5.0.95/my-huge.cnf
/usr/share/doc/mysql-server-5.0.95/my-innodb-heavy-4G.cnf
/usr/share/doc/mysql-server-5.0.95/my-large.cnf
/usr/share/doc/mysql-server-5.0.95/my-medium.cnf
/usr/share/doc/mysql-server-5.0.95/my-small.cnf
/usr/share/mysql/my-huge.cnf
/usr/share/mysql/my-innodb-heavy-4G.cnf
/usr/share/mysql/my-large.cnf
/usr/share/mysql/my-medium.cnf
/usr/share/mysql/my-small.cnf

If one of these files is the basis for your /etc/my.cnf file then you may have this line enabled within it. For example these files have it enabled:

$ grep rehash /usr/share/doc/mysql-server-5.0.95/*
/usr/share/doc/mysql-server-5.0.95/my-huge.cnf:no-auto-rehash
/usr/share/doc/mysql-server-5.0.95/my-innodb-heavy-4G.cnf:no-auto-rehash
/usr/share/doc/mysql-server-5.0.95/my-large.cnf:no-auto-rehash
/usr/share/doc/mysql-server-5.0.95/my-medium.cnf:no-auto-rehash
/usr/share/doc/mysql-server-5.0.95/my-small.cnf:no-auto-rehash

So you'll want to comment this line out if you have it enabled in your /etc/my.cnf file, like so:

#no-auto-rehash

Your alias

Given the method you're employing to call the mysql client using rlwrap you could append the --auto-hash -p switches to it like so:

$ alias mysql='/usr/bin/rlwrap -s 99999 -a -pRED /usr/bin/mysql --auto-rehash -p'
3
  • none of these tricks work. Moreover, I presume you meant --auto-rehash -p not --auto-hash -p in the alias command. But why the -p? (The password to use when connecting to the server) Jan 12, 2014 at 20:04
  • @MartinVegter - yup, I fixed the typo. I always have to provide a password to connect to my MySQL servers.
    – slm
    Jan 12, 2014 at 20:07
  • please see my update Jan 12, 2014 at 20:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .