11

This question is similar to what I'm asking: Is there a way to create an SQL "alias"?

But not quite the same - I'm learning mysql and am going to be running the select command a lot as I screw with different commands. Is there a way I can alias something like:

select * from testdb

to

ls

Or something equally similar? Ideally, I'd be able to alias "select * from" to something like "show" and then just type "show testdb".

1
  • I've searched for such a functionality, but AFAIK it's not possible with the standard mysql client. Commented Nov 24, 2014 at 13:35

2 Answers 2

9

Three ideas come to mind:

  1. a stored procedure, so you'd end up doing "call show('testdb')"

  2. a shell alias, so you run "show testdb" have it map to "mysql -e 'select * from testdb'"

  3. suck it up and type the command.

1

using alias with function can help you pass parameter to a alias like
example query = select * from testdb where param = 'test param'
created alias = sftb test param
to create such alias you can write something like this in your bashrc file.
alias sftb='function sftb(){ mysql -e "select * from testdb where param = '$1'"; };sftb'

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