0

I've installed MySQL 5.7.10 on my Mac using Homebrew. My Mac is running OSX 10.11.3.

When I'm running the MySQL command line client, I cannot tab-complete keywords, table or column names.

How do I get it to tab-complete?

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> 

Here's the output from 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)
  • Maybe this would have been better suited on superuser.com 😕 – JoeNyland Mar 16 '16 at 22:36
  • Probably, but half of the content here is similar. – Thomas Dickey Mar 17 '16 at 22:06
  • You might first use database before you try to auto-complete tables or column names. – Otheus Mar 17 '16 at 22:26
  • 1
    @Otheus Oh my! That's it! Once I use a database, I can tab-complete everything - DBs, columns, tables, etc. However before that, pressing tab does not do anything. Want to add an answer? – JoeNyland Mar 17 '16 at 22:31
1

Tab completion for tables and columns works only when you are connected or using a database that has such tables. When you run mysql and connect to a sever, unless you have specified on the command line (or via cnf files) the database to connect to, you can see only the mysql system tables. Simply execute use mydatabase; to allow all the tables in mydatabase to work with tab-completion. Or connect to the database directly on the command line with

mysql mydatabase
3

If your mysql client is built with readline, you can do this using the auto-rehash feature. These are possible solutions:

  • command-line option --auto-rehash
  • command (in mysql), type rehash
  • configuration file called .my.cnf in your home directory, containing:

    [mysql] auto-rehash

Further reading:

The OSX libedit library is more or less the same as readline (some interface differences with the same functionality). MySQL could be built with either. For example, these mention it:

  • I still don't get tab-completion with the --auto-rehash option. How do I know if I'm using readline? I've installed from Homebrew, if that helps... – JoeNyland Mar 17 '16 at 11:55
  • In OSX, otool can show which shared libraries a program is linked with. – Thomas Dickey Mar 17 '16 at 21:56
  • I've just updated the question with the output form otool -L. Does this help? It means nothing to me, except suggest that I'm not using readline. – JoeNyland Mar 17 '16 at 22:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.