Be Productive with the MySQL Command Line

July 10, 2013

I recently read this short but awesome post titled “Be Productive with the MySQL Command Line“. In the post, the authorĀ Stephane Combaudon, presents three extremely useful tips for when you’re using the command-line MySQL client. The first two in particular are invaluable to me.

The first tip explains how you can paginate SELECT query results, which is pretty great. Just enter the command “PAGER more”, and the client will use the more utility to paginate any future query results. Within the pagination, use more’s commands to control the process from there (e.g., SPACE to get the next page of results, “q” to quit the pagination).

The second tip shows how you can edit commands in your default text editor. Trying to edit problematic queries within the MySQL client is no fun at all. Instead, simply enter “edit”, and the query just executed will be opened in your default text editor. Edit the query there, and then close your editor. You’ll be returned to the MySQL client. Although the edited query won’t appear there, just type “;” and press Enter/Return and the edited query will be executed. Pretty snazzy!

The third tip talks about logging queries and output to a file. I’ll leave it to you to check it out.