Networking

How to install mycli for suggestion-based MySQL typing

If you're a MySQL administrator and you're looking for a tool to make your day-to-day life easier, mycli might be exactly what you need.

mysqlhero.jpg
Image: Jack Wallen

One of the nice things about mobile life is that, while typing, the system will make suggestions, so you can save a bit of time and effort. Imagine, if you will, you could gain the same feature for the MySQL command prompt? As you type, you'd be given suggestions as to what you might want to enter next.

That is actually possible, with the help of the simple to install command line tool called mycli. This handy little tool does one thing and does it to perfection: it auto-completes words, commands, tables, and more. With mycli, you no longer have to commit to memory the vast array of possibilities to be found in the MySQL command line. Instead, start typing and the tool will help you out with smart suggestions.

Let's install mycli and see how it is used.

Installation

The mycli tool works with MySQL and does on a server with or without a GUI (and impressive feat). Know that mycli works on Linux as well as Windows, but does require you to already have your MySQL server up and running. With that said, I will demonstrate this tool on a Ubuntu Server installation.

In order to install mycli, open up a terminal window and issue the following two commands:

sudo apt-get update
​sudo apt-get install mycli

Once the installation is finished, you are ready to start using mycli.

Usage

To make use of mycli, you don't jump into the MySQL prompt as you normally would (such as with the command mysql -u root -p). Instead, you replace mysql with mycli. If you use MySQL with the user root, you would fire up mycli with the command:

mycli -u root

You will be prompted for the MySQL root user password. Upon successful authentication, you will find yourself at the mycli command prompt (Figure A).

Figure A

Figure A

The mycli command prompt ready to go.

Using mycli is exactly as you might expect; start typing and the tool will immediately begin to make suggestions (Figure B).

Figure B

Figure B

Make your choice.

Using the arrow keys, you can scroll down until you land on the suggestion you want to use. Hit Enter on the keyboard to make the selection. To make mycli even more useful, the developer has included smart selections. Say, for instance, you want to switch to a database, but you can't remember what you named the database. Type USE and mycli will present to you a listing of your available databases (Figure C).

Figure C

Figure C

Mycli smart suggestions in action.

That's pretty much it for the bells and whistles on mycli. To be perfectly honest, it doesn't need much more than what it offers.

Once caveat

I did notice one issue. When attempting to connect to mycli from a regular user, the app would segfault and send me back to the standard bash prompt. The only way around that was to first issue the command sudo -s and then issue the command mycli -u root.

A must have tool

For any MySQL database administrator, mycli should be considered a must-have tool. With this single-purpose tool, working with databases gets significantly easier. Give it a try and see if you don't wind up installing mycli on all of your MySQL servers.

Also see

About Jack Wallen

Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.

Editor's Picks

Free Newsletters, In your Inbox