[英]How to setup mysql (@Ubuntu-Server) auto connect to other host?
I am using Ubuntu-server. 我正在使用Ubuntu服务器。 Can I setup / configure 'mysql' to auto-connect to another host? 我可以设置/配置“ mysql”以自动连接到另一台主机吗? I mean if I type mysql on my terminal, it will connect automatically to specific host. 我的意思是,如果我在终端上键入mysql,它将自动连接到特定主机。
Thanks. 谢谢。
There are two parts for the answer. 答案分为两部分。
First - how to make an alias, a word that if you type it, a specific command will execute (taken from here : 首先-如何创建别名,一个单词,如果您键入它,将执行一个特定命令(取自此处 :
Second part - the command you want to run mysql command, it will be something like: 第二部分-您要运行mysql命令的命令,它将类似于:
mysql -u $user -p$passsword -Bse "command1;command2;....;commandn"
You can write a simple wrapper like this: 您可以这样编写一个简单的包装器:
#!/bin/sh
/usr/bin/mysql --user $MYSQL_USER -p $MYSQL_PASSWORD --host $MYSQL_HOST $*
Where that should work almost identically to the default mysql
command with a few tiny exceptions, like how LOAD DATA INFILE
will read files only on the server, not your local machine. 除了一些小小的例外,它应该与默认的mysql
命令几乎相同,例如LOAD DATA INFILE
将如何仅在服务器上而不是本地计算机上读取文件。
You may need to do the same for mysqldump
and other related commands like mysqladmin
if you use those. 如果使用这些命令,则可能需要对mysqldump
和其他相关命令(如mysqladmin
执行相同的操作。
Be sure to specify the actual path to the mysql
binary you want to run. 确保指定要运行的mysql
二进制文件的实际路径。 I'm using /usr/bin/mysql
here but it could be something else. 我在这里使用/usr/bin/mysql
,但这可能是其他东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.