通过SSH直接执行远程命令(这种方式会使用Bash的non-interactive + non-login shell模式)找不到命令
参考:http://ghoulich.xninja.org/2017/05/09/how-to-find-env-vars-with-ssh-remote-exec-commands/
ssh root@ip1 "/usr/local/mysql/bin/mysqld_multi --defaults-extra-file=/etc/mysql/3306.cnf --no-log start 3306" WARNING: my_print_defaults command not found. Please make sure you have this command available and in your path. The command is available from the latest MySQL distribution. ABORT: Can't find command 'my_print_defaults'. This command is available from the latest MySQL distribution. Please make sure you have the command in your PATH.
问题
操作ip2却没有报此错误,而且其配置文件~/.bashr中也没有关于mysql环境变量的配置
原因
non-interactive + non-login shell模式的bash执行的配置文件是~/.bashr而不是~/.bash_profile
mysqld_multi会调用my_print_defaults命令,而且不会带上绝对路劲
发现ip2机器上比ip1多了个/usr/bin/my_print_defaults
[root@ip2 mysql]# rpm -qf /usr/bin/my_print_defaults mysql-5.1.73-8.el6_8.x86_64
原来是是通过rpm包安装的
解决方法
[root@ip1 ~]# ln -s /usr/local/mysql/bin/my_print_defaults /usr/bin