MySQL command-line client has an option for table names/fields auto-complete. Moreover, it is enabled by default (at least it says so in manual, on my Slackware box it wasn’t). This feature is called auto-rehash – when typing names you simply can hit TAB to see all possible alternatives for auto-completion (if there’s exactly one alternative, then auto-complete would occur without further intervention). Command-line folks would find this quite handy, indeed, if you are using CLI a lot, you just get used to hitting TAB key when in doubt.
So, if it’s not enabled in your client by default, you can enable this by issuing auto-rehash option when invoking the mysql client:
mysql -uroot -p --auto-rehash
Please note that you have to invoke use DBNAME at least once, since that’s the point when MySQL does hashing. Otherwise feature would refuse to do its work.
Of course, you can have auto-rehash (or no-auto-rehash for that matter) option in your ini file if you like:
[mysql] auto-rehash
Particular drawback of auto-rehashing is slower start up time of client, since data has to be read and hashed for this functionality to work. If that troubles you, I have a good news: you do not have to use –auto-rehash option on start up at all, and you can still get auto-completion, even if –no-auto-rehash option was used. It’s quite simple, just type one of
\# or REHASH
in your MySQL client and rehash would occur, allowing you to utilize auto-complete. Personally, I prefer this alternative if my interactions with database are not so often, otherwise I still think that starting with –auto-rehash is easier, and speed penalty is not that big.




Thank you so much!
Surprisingly, Mac OS X Snow Leopard has this enabled, that’s how I found out about it.
Ubuntu does not have this enabled, but you’re tip worked perfectly.
Thank you so much!
One interesting note: if you type the table name, then the field, auto-complete works a lot better.
ex: SELECT * FROM table1 WHERE table1.field1 = ‘a’
after typing the ‘.’, and typing ‘f’ then tab, auto-completes to field1
Thanks for the tip, worked a treat.
Curiously I have the opposite situation to Kearney – my home ubuntu machine has always had this enabled by default, but my Mac at work did not!