mysql导入sql文件的cmd命令为:
mysql -uroot -p密码 -D数据库名<sql文件全路径
但是当数据库的密码为空时,应该这样:
mysql -uroot -D数据库名<sql文件全路径
mysql -uroot -p密码 -D数据库名<sql文件全路径
但是当数据库的密码为空时,应该这样:
mysql -uroot -D数据库名<sql文件全路径
附上c#运行cmd的方法:
public static Process RunCmd(String cmd, Boolean showWindow)
{
var p = new Process();
var si = new ProcessStartInfo();
var path = Environment.SystemDirectory;
path = Path.Combine(path, @"cmd.exe");
si.FileName = path;
if (!cmd.StartsWith(@"/")) cmd = @"/c " + cmd;
si.Arguments = cmd;
si.UseShellExecute = false;
si.CreateNoWindow = !showWindow;
si.RedirectStandardOutput = true;
si.RedirectStandardError = true;
p.StartInfo = si;
p.Start();
return p;
}
Process p = RunCmd("mysql -uroot -D数据库名<sql文件全路径"), false);
p.WaitForExit();
string output = p.StandardError.ReadToEnd();
if (!string.IsNullOrWhiteSpace(output))
{
Console.WriteLine(output<span style="font-family: Arial, Helvetica, sans-serif;">);</span>
}
output = p.StandardOutput.ReadToEnd();
if (!string.IsNullOrWhiteSpace(output))
{
Console.WriteLine(output<span style="font-family: Arial, Helvetica, sans-serif;">);</span>
}
p.Close();