StringBuilder commandinfo = new StringBuilder();
commandinfo.AppendFormat("");//3306-端口号、111111-数据库等密码、test-我的数据库名称
String exportCommand = commandinfo.ToString();
String mysqlDirecroty = @"C:\Program Files (x86)\MySQL\MySQL Server 5.5\bin";
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.WorkingDirectory = mysqlDirecroty;
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;//是否显示CMD窗口
p.Start();
p.StandardInput.WriteLine("mysql -uroot -p111111");//111111-数据库等密码
p.StandardInput.WriteLine("use test");//切换数据库为test
p.StandardInput.WriteLine("alter table user add UserID int(11) default 0;");//为表user添加一列Userid
p.StandardInput.WriteLine("exit");