正如我从 documentation 中看到的那样, 最基本形式的导入命令是:
mysql.exe < example.sql
当我在 Windows 中从命令行运行它时它起作用了。但是当我启动进程时它不起作用mysql.exe
与 < example.sql
参数。例如,创建快捷方式并将其路径设置为 mysql.exe < example.sql
不起作用,它只打印 mysql.exe
的帮助信息.
作为旁注,我在尝试运行以下 C# 代码时首先注意到这个问题:
new Process
{
StartInfo = new ProcessStartInfo
{
FileName = "mysql.exe",
Arguments = "< example.sql",
}
}.Start();
最佳答案
部分< example.sql
不构成 mysql.exe
的参数; <
字符表示 redirection运算符,所以文件的内容 example.sql
被重定向到 mysql.exe
.
我想您必须将文件名更改为 cmd.exe
和 /C "mysql.exe < example.sql"
的参数.考虑指定所有文件的完整绝对路径。
关于Mysql 导入命令在 cmd 上运行时有效,但在直接传递参数时无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40502911/