gpt4 book ai didi

mysql - 有没有办法在 ssh 中设置变量?

转载 作者:可可西里 更新时间:2023-11-01 07:55:21 24 4
gpt4 key购买 nike

我仍在努力解决这个问题,但是有没有我可以用来设置一些简单变量的函数/命令?

当我已经通过 ssh 登录时,登录到 mysql 会更快,但是输入完整的连接字符串有点烦人。

任何方式来做类似的事情:

mysql ${variable} dbname

其中 variable 类似于 -u user -p -h hostname

或者,是否有其他方法可以满足我的需要?

最佳答案

在您的~/.bash_profile(在服务器上)中创建别名~/.bash_profile 中的更改将在您下次登录时生效。

例如添加

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

然后通过

使用它
ssh yourServer conMy dbname

或者当已经登录时,只需:

conMy dbname

来自 bash 联机帮助页:

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.

关于mysql - 有没有办法在 ssh 中设置变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/670919/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com