tags:

views:

122

answers:

2

Still working my way around this, but is there any function/command I can use to set some simple variables?

Logging into mysql is quicker when I'm already ssh'd in, but typing in the full connection string is a bit annoying.

Any way to do something like:

mysql ${variable} dbname

Where variable would be something like -u user -p -h hostname

Or, is there another way to do what I need?

+7  A: 

Create alias in your ~/.bash_profile (on the server). Changes in ~/.bash_profile will have effect the next time you log in.

For example add

alias conMy='mysql -u user -p -h hostname'

And then use it via

ssh yourServer conMy dbname

or when already logged on, just:

conMy dbname


From the bash manpage:

alias [-p] [name[=value] ...] Alias with no arguments or with the -p option prints the list of aliases in the form alias name=value on standard output. When arguments are supplied, an alias is defined for each name whose value is given. A trailing space in value causes the next word to be checked for alias substitution when the alias is expanded. For each name in the argument list for which no value is supplied, the name and value of the alias is printed. Alias returns true unless a name is given for which no alias has been defined.

vartec
Tried it out, created a file at the location but it doesn't seem to work. Comes up with conMy: command not found. Not sure if it's a permission thing or just a server setting.
damnitshot
In your home dir (on the server) do "ls -a". See if there are any files like .bashrc, .profile or .bash_profile. These names start with . (a dot). Also, check which shell you're using with "echo $SHELL"
vartec
Theres a .bash_history and a .bash_profile (but I created that one with touch). $SHELL = /bin/bash
damnitshot
Well, then it should work. What exactly did you put in .bash_profile?
vartec
<pre>alias conMy='mysql -u username -h hostname -p'</pre>That's it. Only text in the file (with hostname/username blanked out. hostname has hyphens and dots in it if that'd affect it at all)
damnitshot
Have you re-logged after changing that file?
vartec
Woooo! That did it. Thanks a bunch for the help, you've saved me a lot of time ;D
damnitshot
A: 

This isn't related to ssh. You have to set the variables in your shell.

Geo