1
有没有办法将连接参数(如主机,端口,用户名,密码,数据库)保存到我经常作为快捷键访问的mysql服务器?mysql连接配置文件配置文件
我正在寻找类似于ssh config为从Ubuntu终端的MySQL。最好还带有ssh隧道支持。
有没有办法将连接参数(如主机,端口,用户名,密码,数据库)保存到我经常作为快捷键访问的mysql服务器?mysql连接配置文件配置文件
我正在寻找类似于ssh config为从Ubuntu终端的MySQL。最好还带有ssh隧道支持。
你可以使用--defaults-file选项与外壳别名, 结合,例如:
% cat db01
[mysql]
user=root
password=<your_pwd>
host=<your_host>
% alias my_db01='mysql --defaults-file=db01'
% my_db01
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 41
Server version: 5.1.54-1ubuntu4 (Ubuntu)
Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
This software comes with ABSOLUTELY NO WARRANTY. This is free software,
and you are welcome to modify and redistribute it under the GPL v2 license
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql>
所以你可以创建具有不同设置不同的文件。
我可以直接为mysql -uuser -ppassword -hhost添加别名,而不是使用文件。但是,那不是我正在寻找的。谢谢你的回答 –
是的,你可以。应该注意的是,在这种情况下,在某些操作系统中,您的密码将在ps命令输出中清晰可见。如果你想避免一个单独的文件,并且你的shell支持进程替换,你可以使用像这样的东西:'mysql --defaults-file = <(printf'[mysql] \ nuser =%s \ npassword =%s \ n'用户传递)',所以在ps输出是:'mysql> \! pgrep -lf mysql \ 6312 mysql --defaults-file =/dev/fd/63'。 –