繁体   English   中英

mysql授予ssh权限

[英]mysql grant privileges over ssh

命令:

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用法的信息:用法:mysql [OPTIONS] [数据库] - ?, - help显示此帮助并退出。

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.弱引用:双引号

例如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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM