有件事巴什不喜欢。应该逃什么,怎么逃?
mysql --user=root --password=mypass vsftpd << EOF
GRANT ALL PRIVILEGES ON `MYUSERNAME\_%`.* TO 'MYUSERNAME'@'%';"
EOF
我得到以下错误:
-bash: MYUSERNAME_%: command not foundERROR 1064 (42000) at line 1: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* TO 'MYUSERNAME'@'%'' at line 1
最佳答案
backticks执行命令替换(与$()
相同)。尝试在外层使用单引号,在用户名和主机名中使用双引号:
mysql --user=root --password=mypass vsftpd 'GRANT ALL PRIVILEGES ON `MYUSERNAME\_%`.* TO "MYUSERNAME"@"%";'
您可以在这里指示doc不要通过引用分隔符来展开变量,但我不确定这是否也适用于命令替换:
mysql --user=root --password=mypass vsftpd << 'EOF'
GRANT ALL PRIVILEGES ON `MYUSERNAME\_%`.* TO 'MYUSERNAME'@'%';"
EOF