我正在关注 instructions来自 mysql 站点,关于在 Windows 机器上重置 mysql 服务器的密码。
逐字复制命令:
C:\> "C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt.exe"
--defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.0\\my.ini"
--init-file=C:\\mysql-init.txt
给我这个错误(缩写):
Unexpected token 'defaults-file="C:\Program Files\MySql\Mysql Server 5.0\my.ini"'
in expression or statement.
The '--' operator works only on variables or on properties.
+ CategoryInfo :ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId :UnexpectedToken
我环顾四周,发现 this建议:
Try this:
$cmd= {cmd /c 'C:\Program Files\PostgreSQL\8.3\bin\pg_dump.exe "--encoding=UTF8 --verbose --create --username=postgres -- file=C:\db\Wednesday.pg DB"'}
&$cmd
-- is the Powershell decrement operator. To make it "mundate", it needs to be enclosed in single quotes to suppress parsing it as an operator. You could also escape all the hyphens with backticks, but that's going to get really ugly.
我试过按照那种格式..即
$cmd = {cmd /c 'C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt.exe
"--defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.0\\my.ini
--init-file=C:\\mysql-init.txt"'}
&$cmd
但是我得到了这个错误:
'C:\Program' is not recognised as an internal or external command
我也试过做回勾转义:
C:\> "C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt.exe"
`-`-defaults-file="C:\\Program Files\\MySQL\\MySQL Server 5.0\\my.ini"
`-`-init-file=C:\\mysql-init.txt
但也有一个错误(缩写):
unexpected token '`-`-defaults-file.. ' in expression or statement
有什么想法吗?
最佳答案
用于停止参数处理的双破折号对于 Powershell 来说确实是一个可悲的选择。 我试图通过 Invoke-Command 让它工作,但下面的例子效果最好
&"C:\Program Files\MySQL\MySQL Server 5.0\bin\mysqld-nt.exe" '--defaults-file=""C:\Program Files\MySQL\MySQL Server 5.0\my.ini""' '--init-file="C:\mysql-init.txt"'
双引号之间的可执行文件。
以及单引号之间的每个参数,双引号之间的参数值(或双引号使路径中的空格有效)
关于mysql - 如何绕过 '--' 运算符仅适用于变量或属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22192440/