命令:
ssh xxx.xxx.xxx.xxx \"mysql -u root -password \\\"grant all privileges on rcf_275d315.* to rfc_user@localhost identified by \'W27j453frxrff23\'\\\"\"
给了我一个错误:
bash: mysql -u root -p97yf2beiru3trf289 "grant all privileges on rcf_275d315.* to rfc_user@localhost identified by 'W27j453frxrff23'": command not found
当我复制bash返回的字符串时,在本地结束运行它是有效的。当粘贴在远程服务器上时也可以工作。
由于某种原因,它无法在ssh上运行,并返回错误:
mysql -u root -p97yf2beiru3trf289 "grant all privileges on rcf_275d315.* to rfc_user@localhost identified by 'W27j453frxrff23'": command not found
我尝试了一些变化,没有成功:
ssh xxx.xxx.xxx.xxx \"mysql -u root -pBOY8o7ubio87gubip7 \\\"grant all privileges on rfc_275d315.* to rfc_user identified by \'KUG34dY976fyvc768g\'\\\"\"
结果:
bash: mysql -u root -pBOY8o7ubio87gubip7 "grant all privileges on rfc_275d315.* to rfc_user identified by 'KUG34dY976fyvc768g'": command not found
ssh xxx.xxx.xxx.xxx \"mysql -u root -pBOY8o7ubio87gubip7 \\"grant all privileges on rfc_275d315.* to rfc_user identified by \'KUG34dY976fyvc768g\'\\"\"
结果:
bash: -c: line 0: unexpected EOF while looking for matching `"'
bash: -c: line 1: syntax error: unexpected end of file
ssh xxx.xxx.xxx.xxx mysql -u root -pBOY8o7ubio87gubip7 \\"grant all privileges on rfc_275d315.* to rfc_user identified by \'KUG34dY976fyvc768g\'\\"
结果:
mysql Ver 14.14 Distrib 5.1.66, for redhat-linux-gnu (x86_64) using readline 5.1
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
所有者。
Usage: mysql [OPTIONS] [database]
-?, --help Display this help and exit.
ssh xxx.xxx.xxx.xxx mysql -u root -pBOY8o7ubio87gubip7 \\\"grant all privileges on rfc_275d315.* to rfc_user identified by \'KUG34dY976fyvc768g\'\\\"
结果:
mysql Ver 14.14 Distrib 5.1.66, for redhat-linux-gnu (x86_64) using readline 5.1
Copyright (c) 2000, 2012, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
所有者。
Usage: mysql [OPTIONS] [database]
-?, --help Display this help and exit.
仍然,不要问题出在哪里。谢谢你的帮助。
更新: 当echo保存到文件时: ssh xxx.xxx.xxx.xxx“echo mysql -u root -piugiu -e \\”将rfc_275d315。*的所有权限授予由''in76bn6bgb876n \'\\“> rfc / echo.txt”标识的rfc_user / p>
我在文件中得到这个: mysql -u root -piugiu -e“将rfc_275d315。*的所有权限授予由'in76bn6bgb876n'标识的rfc_user”
这是正确的命令,当复制并粘贴到远程服务器上的命令行时,它可以正常工作。
删除echo时: ssh xxx.xxx.xxx.xxx“mysql -u root -piugiu -e \\”将rfc_275d315。*的所有权限授予由''in76bn6bgb876n \'\\“> rfc / echo.txt”
文本文件包含有关mysql用法的信息: 用法:mysql [OPTIONS] [数据库] - ?, - help显示此帮助并退出。
答案 0 :(得分:2)
ssh xxx.xxx.xxx.xxx 'mysql -u root -pBOY8o7ubio87gubip7 -e "grant all privileges on rfc_275d315.* to rfc_user@localhost identified by '\''KUG34dY976fyvc768g'\''" yourdatabase'
应该有效。您忘记了MySQL客户端参数中的-e
,它允许您传递语句
编辑1:
固定报价
在bash中,您可以区分两种引用方式(就像在许多其他语言中一样)
<强> 1。弱引用:双引号
e.g。 echo "$PATH"
在弱引用的字符串中没有
的解释
- 空格作为单词分隔符
- 路径名扩展
- 流程替换
- 引用强引号的单引号
- 模式匹配的字符
否则参数扩展完成:
ls -l "*"
不会被解释,除非你有一个名为*
*
并导致错误
echo "Your PATH is: $PATH"
将按预期工作。解释$PATH
<强> 2。强烈引用:单引号
在单引号内,您根本得不到任何解释。单引号内的所有字符都被视为文本。
如果您必须在单引号文本中使用单引号,则仅仅转义是不够的。你必须像这样结束:
QUERY='SELECT * FROM myTable WHERE col1 = '
\'
'value1'
\'
答案 1 :(得分:0)
您无需引用发送给ssh
的命令。