mysql - Powershell : Convert MariaDB query to String

标签 mysql string powershell mariadb

你能帮我将下面的查询转换成字符串 $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/

相关文章:

powershell - 八达通部署缓存

php - mysqli_error 和 mysqli_stmt_error 的区别

php - Laravel 4 查询

c - 如何将字符串分隔为不同的类型、can 信号?

Powershell goto语句替换

sql-server - 从 powershell 删除 SQL Server 数据库

php - 尽管使用了许多网站的建议,但 SQL 中的变量仍无法识别

java - 插入 blob 作为数据类型时出现数据截断错误

java - 如何将字符串拆分为列表并在一行 Java 中进行修剪

c++ - 使用 << 运算符构造 std::string