nixCraft Poll

Topics

Save time use MySQL auto completion for database or table names

Posted by Vivek Gite [Last updated: January 16, 2007]

There is a quick way to type both MySQL database and table names quickly by enabling MySQL auto completion feature. This is called automatic rehashing. This option is on by default, which enables table and column name completion.

First connect to mysql database called foo:

$ mysql -u vivek -p foo
Now let us say you would like to list all records from tables wp_users. Type select * from w and press tab key to complete table name:
mysql> select * from w {Press TAB KEY}

Please note that if the partial name is unique, mysql will completes it for you. Otherwise, you can hit tab key again to see all possible matches.

Auto-completion enables you to cut down typing time and great way to speed up your work :)

If you don't use this feature, disable this feature by passing -A or --skip-auto-rehash option to mysql. That causes mysql to start faster.
$ mysql -A -u vivek -p foo

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. Sheeri Says:

    Great tip! You do have to have done a “use database” at least once before in your session, because that’s when it loads all that information in. Also, does that trick work on Unix only or on Windows too? (Mac OS X = Unix)

  2. nixcraft Says:

    Hmm..

    mysql -u vivek -p foo

    foo is database name; so no need to use database name again (foo is not my password) :). Otherwise execute use database as suggested by you.

    I have not tested this on Microsoft Windows. But it should work as this is mysql client feature.

    Appreciate your post.

  3. mysqlonWindows Says:

    This doesn’t appear to work on Windows with cmd.exe. Does anyone know if it’s possible to get mysql tab-completion working with cmd.exe? If it is, then any additional guidance on how to get it set up would be great.

  4. Paolo Says:

    can be possible autocomplete sql command?!
    for example: select, from, having and so way?
    thanks a lot
    bye

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.