Tab 补全在 MySQL 命令行客户端中不起作用

Tab 补全在 MySQL 命令行客户端中不起作用

我已经使用 Homebrew 在 Mac 上安装了 MySQL 5.7.10。我的 Mac 运行的是 OSX 10.11.3。

当我运行 MySQL 命令行客户端时,我无法使用制表符补全关键字、表名或列名。

我怎样才能让它完成制表符?

joenyland@Joes-MBP ~ $ mysql --auto-rehash
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 10
Server version: 5.7.10 Homebrew

Copyright (c) 2000, 2015, 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> 

这是以下的输出otool

joenyland@Joes-MBP ~ $ otool -L /usr/local/bin/mysql
/usr/local/bin/mysql:
    /usr/lib/libedit.3.dylib (compatibility version 2.0.0, current version 3.0.0)
    /usr/local/opt/openssl/lib/libssl.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/local/opt/openssl/lib/libcrypto.1.0.0.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

答案1

仅当您连接或使用具有此类表的数据库时,表和列的制表符补全才有效。当您运行mysql并连接到服务器时,除非您在命令行(或通过 cnf 文件)指定了要连接的数据库,否则您只能看到 mysql 系统表。只需执行use mydatabase;即可允许所有表使用mydatabase制表符完成功能。或者直接在命令行上连接数据库

mysql mydatabase

答案2

如果您的mysql客户端是使用 构建的readline,则可以使用该auto-rehash功能来执行此操作。这些是可能的解决方案:

  • 命令行选项--auto-rehash
  • 命令(在mysql)中,输入rehash
  • .my.cnf在您的主目录中调用的配置文件,包含:

    [mysql] 自动重新哈希

进一步阅读:

OSX libedit 库或多或少与 readline 相同(具有相同功能的一些界面差异)。 MySQL 可以用其中任何一个来构建。例如,这些提到了它:

相关内容