rlwrap:mysql 自动完成功能不起作用

rlwrap:mysql 自动完成功能不起作用

通常,自动补全在 mysql 命令行客户端 ( mysql-client-5.5) 中运行良好。我有一张名为 的表booking。当我输入字母b并按下时,TAB我的表的名称会自动完成:

SELECT * FROM b<TAB>

但是,当我使用rlwrap( alias mysql='/usr/bin/rlwrap -s 99999 -a -pRED /usr/bin/mysql') 时,自动完成功能将停止工作。

看起来好像rlwrap干扰了自动完成功能。

我正在使用 Debian Wheezy。

更新1:

当我用 开始命令时strace,即:

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

我看到以下错误

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

rlwrap 可能需要一些带有 mysql 补全的文件吗?

更新2

好的,我已经创建了该文件/usr/share/rlwrap/completions/mysql并在其中放置了 3 个示例行:

select
from
where

现在,当我开始mysql输入时sele<TAB>,选项卡实际上完成了单词select。这是进步,但这并不能解决全部问题。我主要需要自动完成功能来帮助我完成我不(不想)记住的晦涩表名。但每次更改/添加/重命名表时,我无法编辑自动完成文件。

是否无法告诉rlwrap使用相同的自动完成文件mysql? (我想mysql必须使用一些这样的文件)

更新3:

以下是其他错误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)

答案1

这将在普通 mysql 服务器上启用完成功能:

mysql --auto-rehash

对于rlwrap,检查您是否已RLWRAP_HOME设置。看这里了解更多信息。该页面还报告如果您的系统太忙,可能会出现竞争状况。

答案2

编辑my.cnf

[mysql]
auto-rehash

如果这不起作用,请将其添加到debian.cnf

即使你也可以做到:

mysql> \#

答案3

我在 FreeBSD 论坛上找到了这一点,但它也应该适合您的情况。论坛帖子的标题是:为什么 bash 中的 mysql 没有自动完成功能?

该线程中提到的解决方案如下。

选项#1 - 通过 mysql 客户端

$ mysql --auto-rehash -p

这直接来自mysql手册页。

--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.

选项#2 - 通过服务器

您还可以通过在服务器文件中注释掉相同的功能行来在服务器端修复此问题/etc/my.cnf。这取决于您的my.cnf文件来自哪里。 MySQL 提供了几个开箱即用的示例.cnf文件。

例子

这是在我的 CentOS 系统上,购买你的 Debian 系统可能也有这些。

$ 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

如果这些文件之一是您的文件的基础/etc/my.cnf,那么您可能会在其中启用此行。例如,这些文件已启用它:

$ 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

因此,如果您在文件中启用了该行,则需要注释掉该行/etc/my.cnf,如下所示:

#no-auto-rehash

你的别名

鉴于您用来调用 mysql 客户端的方法,rlwrap您可以将--auto-hash -p开关附加到它,如下所示:

$ alias mysql='/usr/bin/rlwrap -s 99999 -a -pRED /usr/bin/mysql --auto-rehash -p'

相关内容