0

命令:

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 标识的 rfc_user /echo.txt"

我在文件中得到这个: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 标识的 rfc_user "

文本文件包含有关 mysql 使用的信息: Usage: mysql [OPTIONS] [database] -?, --help 显示此帮助并退出。

4

2 回答 2

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'

应该工作。您忘记了-e允许您传递语句的 MySQL 客户端参数

编辑1:

固定报价

在 bash 中,您可以使用两种不同的引用方式(就像在许多其他语言中一样)

1.弱引用:双引号

例如echo "$PATH"

在弱引用的字符串中,没有解释

  • 空格作为单词分隔符
  • 路径名扩展
  • 过程替代
  • 单引号引入强引用
  • 用于模式匹配的字符

否则参数扩展完成:

ls -l "*"

不会被解释,会按*字面意思传递,除非你有一个名为的文件,否则会导致错误*

echo "Your PATH is: $PATH"

将按预期工作。$PATH被解释

2. 强引用:单引号

在单引号内,您根本没有任何解释。单引号内的所有字符都被视为文本。

如果您必须在单引号文本中使用单引号,则仅转义是不够的。你必须像这样连接:

QUERY='SELECT * FROM myTable WHERE col1 = ' \' 'value1' \'

来源:http ://wiki.bash-hackers.org/syntax/quoting

于 2012-12-08T13:13:44.423 回答
0

您不需要引用您发送到的命令ssh。删除命令周围的最外层引用mysql,它应该可以正常工作。

于 2012-12-08T02:29:07.577 回答