mysql - 如何绕过 '--' 运算符仅适用于变量或属性

标签 mysql windows powershell escaping

我正在关注 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/

相关文章:

php - 使用for循环和mysql更新数据库

php - 如何通过php和mysql上传图像文件

php - 我如何清除先前回显的结果而不影响 php 中的任何其他功能?

c# - 软件 GUID 是否应该与程序集 GUID 不同?

powershell 合并 csv 的

php - sql php函数中的插入查询

windows - 用于查找已安装设备的驱动器号的批处理脚本

c# - UWP 应用程序中应使用哪个命名空间类 HttpClient?

windows - 如何在PowerShell中查询Windows 10设备的经纬度?

powershell - Powershell ForEach循环间歇性工作-工作,失败,工作,失败,工作等