你能帮我将下面的查询转换成字符串 $query 吗?
$arg1 = "--user=root"
$arg2 = "--password=" + $dbPsw
$query = @("INSERT INTO `characters` (`account_name`,`obj_id`,`char_name`,`phone`) VALUES ('John',1000,'John',1234567890);")
$arg3 = "--execute="+ $query
Start-Process "mysql.exe " -ArgumentList @($arg1,$arg2,$arg3)
或者溅起来。 Mysql仅返回命令列表
非常感谢
最佳答案
我认为您不需要Start-Process
。只需运行命令即可。 (毕竟,PowerShell 是一个 shell。shell 的工作之一就是运行您输入的命令。)
需要注意的一件事是,反引号 (`) 字符是 PowerShell 中的转义字符,因此您必须将其加倍:
mysql "--user=root" "--password=$dbPsw" "--execute=INSERT INTO ``characters`` (``account_name``,``obj_id``,``char_name``,``phone``) VALUES ('John',1000,'John',1234567890);"
如果mysql
命令不在路径中,则需要指定它的路径;例如:
C:\MYSQL\mysql "--user=root" ...
如果mysql.exe
程序位于包含空格的路径中,则使用调用(&
)运算符;例如:
& "C:\Program Files\MYSQL\mysql.exe" "--user=root" ...
关于mysql - Powershell : Convert MariaDB query to String,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59669480/