1.简单实例

//备份还原mysql
public static void TestOne()
{
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
//指定MySql程序的bin 目录
p.StartInfo.WorkingDirectory = @"E:\mysql-5.6.26-winx64\bin";
p.Start(); /*************
* 备份命令
**************/
//简单格式
//string strSql = "mysqldump --quick --host=localhost -u root -p123 test > d:\\test_20151227110010.sql";
/*命令指定格式*/
//String command = "mysqldump --quick --host=localhost --default-character-set=gb2312 --lock-tables --verbose --force --port=端口号 --user=用户名 --password=密码 数据库名 -r 备份到的地址";
//string strSql = "mysqldump --quick --host=localhost --default-character-set=gb2312 --lock-tables --verbose --force --port=3306 --user=root --password=123 test -r d:\\one.sql"; /*************
* 还原命令
**************/
//简单格式
//string strSql = "mysql --host=localhost -u root -p123 test < d:\\test_20151227110010.sql";
/**还原命令格式**/
//string s = "mysql --host=localhost --default-character-set=gbk --port=端口号 --user=用户名 --password=密码 数据库名<还原文件所在路径";
string strSql = "mysql --host=localhost --port=3306 --user=root --password=123 test < d:\\test_20151227110010.sql"; p.StandardInput.WriteLine(strSql + " &exit");
p.StandardInput.AutoFlush = true; /****执行命令,没有返回可验证的结果*****/
//显示方式1
//StreamReader reader = p.StandardOutput;
//string line = reader.ReadLine();
//while (!reader.EndOfStream)
//{
// Console.WriteLine(line);
// line = reader.ReadLine();
//} //显示方式2
string result = p.StandardOutput.ReadToEnd();
Console.WriteLine(result); //返回警告结果 --Warning: Using a password on the command line interface can be insecure.
string result2 = p.StandardError.ReadToEnd();
Console.WriteLine(result2); //显示方式3
ShowValue(p); p.WaitForExit();
p.Close();
} private static async void ShowValue(Process p)
{
string result = await p.StandardOutput.ReadToEndAsync();
Console.WriteLine(result);
}

C#程序调用cmd执行命令-MySql备份还原的更多相关文章

  1. c# 程序调用cmd执行命令如SVN.exe

    c# 程序调用cmd执行命令如SVN.exe string str = Console.ReadLine(); System.Diagnostics.Process p = new System.Di ...

  2. C#程序调用CMD执行命令,将参数传递给cmd.exe

    proc.StartInfo.Arguments = "/c ping 10.2.2.125"; C#程序调用CMD执行命令 将参数传递给cmd.exe的(Passing an a ...

  3. C#程序调用cmd执行命令

    对于C#通过程序来调用cmd命令的操作,网上有很多类似的文章,但很多都不行,竟是漫天的拷贝.我自己测试整理了一下. 代码: string str = Console.ReadLine(); Syste ...

  4. C#程序调用cmd执行命令(转)

    C#通过程序来调用cmd命令的操作 string str = Console.ReadLine(); System.Diagnostics.Process p = new System.Diagnos ...

  5. C# 调用CMD执行命令行

    这几天用c#做了一个项目,其中一个功能是要把生成的临时文件隐藏,同时,不能在屏幕上有调用CMD的痕迹,这里生成的临时文件的绝对路径为delfile为文件的绝对路径, 代码如下: private voi ...

  6. C# 调用cmd执行命令

    private void CmdRun_Click(object sender, EventArgs e)        {            Process p = new Process(); ...

  7. linux 程序调用system执行命令

    正确使用system方法,判断返回值 int exeCmd(const char *cmd) { pid_t status; status = system(cmd); == status) { Wr ...

  8. java调用cmd执行maven命令

    一.原理介绍 Java的Runtime.getRuntime().exec(commandStr)可以调用执行cmd指令. cmd /c dir 是执行完dir命令后封闭命令窗口. cmd /k di ...

  9. (4.8)mysql备份还原——binlog查看工具之show binlog的使用

    (4.8)mysql备份还原——binlog查看工具之mysqlbinlog及show binlog的使用 关键词:show binlog,mysql binlog查看,二进制文件查看,binlog查 ...

随机推荐

  1. 关于laravel框架的Auth::attempt验证失败

    按照官方文档进行认证 发现不管怎么样都是失败 if (Auth::attempt(array('email' => $email, 'password' => $password), tr ...

  2. jquery 获取 outerHtml 包含当前节点本身的代码

    在开发过程中,jQuery.html() 是获取当前节点下的html代码,并不包含当前节点本身的代码,然后我们有时候确需要,找遍jQuery api文档也没有任何方法可以拿到. 看到有的人通过pare ...

  3. How To Learn English Very Fast

    How do you learn English very fast? Every week, I get emails about this topic.   Typically, someone ...

  4. 清除IE下链接虚线框

    方法一:利用javascript的onfocus事件,实现如下: Html代码 <a href="http://www.www.baidu.com"  onfocus=&qu ...

  5. [算法]线段树(IntervalTree)

    转载请注明出处:http://www.cnblogs.com/StartoverX/p/4617963.html 线段树是一颗二叉搜索树,线段树将一个区间划分成一些单元区间,每一个区间对应线段树的一个 ...

  6. Linux编译错误集

    1.编译驱动: FATAL: modpost: GPL-incompatible module ArmGpioDriver.ko uses GPL-only symbol 'class_destroy ...

  7. iTween visual Editor 0.6.1

    首先添加ITween Path编辑路径(无需路径运动的动画可忽略该步骤): 然后为需要添加动画的物体添加ITween Event脚本: 若是物体沿特定路径运动,则选中Path,并选择一个路径:  若想 ...

  8. ACM2055_ctype.h_cctype

    #include<iostream> int main() { using namespace std; int y,count; char x; cin>>count; wh ...

  9. [LeetCode] 55. Jump Game 解题思路

    Given an array of non-negative integers, you are initially positioned at the first index of the arra ...

  10. cocos2d-x游戏开发(十七)NDK+ant编译暗黑世界

    个人原创,欢迎转载http://blog.csdn.net/dawn_moon/article/details/12308967 9秒论坛的客户端暗黑世界,ios已经跑过了,今天搞了一下安卓的,记录一 ...