我想使用Powershell运行一个mysql命令,但由于重音符号(`)而出现语法错误。
mysql -u root -p -e "GRANT ALL PRIVILEGES ON `testuser\_%` . * TO 'testuser'@'localhost';"
mysql : ERROR at line 1: Unknown command '\_'.
At line:1 char:1
+ mysql -u root -e "GRANT ALL PRIVILEGES ON `testuser\_%`.* TO ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (ERROR at line 1: Unknown command '\_'.:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
看起来Powershell会混淆此部分`testuser\_%`
或\_%
有任何建议吗?
Let MySQL users create databases, but allow access to only their own databases
答案 0 :(得分:0)
是的,因为反击
`
是PowerShell中的文字转义字符。
您可以使用单引号来定义字符串
这样做怎么样?
$query = 'GRANT ALL PRIVILEGES ON `testuser\_%` . * TO testuser@localhost'
mysql -uroot -p -e "$query"