C#程序调用cmd执行命令-MySql备份还原
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备份还原的更多相关文章
- c# 程序调用cmd执行命令如SVN.exe
c# 程序调用cmd执行命令如SVN.exe string str = Console.ReadLine(); System.Diagnostics.Process p = new System.Di ...
- C#程序调用CMD执行命令,将参数传递给cmd.exe
proc.StartInfo.Arguments = "/c ping 10.2.2.125"; C#程序调用CMD执行命令 将参数传递给cmd.exe的(Passing an a ...
- C#程序调用cmd执行命令
对于C#通过程序来调用cmd命令的操作,网上有很多类似的文章,但很多都不行,竟是漫天的拷贝.我自己测试整理了一下. 代码: string str = Console.ReadLine(); Syste ...
- C#程序调用cmd执行命令(转)
C#通过程序来调用cmd命令的操作 string str = Console.ReadLine(); System.Diagnostics.Process p = new System.Diagnos ...
- C# 调用CMD执行命令行
这几天用c#做了一个项目,其中一个功能是要把生成的临时文件隐藏,同时,不能在屏幕上有调用CMD的痕迹,这里生成的临时文件的绝对路径为delfile为文件的绝对路径, 代码如下: private voi ...
- C# 调用cmd执行命令
private void CmdRun_Click(object sender, EventArgs e) { Process p = new Process(); ...
- linux 程序调用system执行命令
正确使用system方法,判断返回值 int exeCmd(const char *cmd) { pid_t status; status = system(cmd); == status) { Wr ...
- java调用cmd执行maven命令
一.原理介绍 Java的Runtime.getRuntime().exec(commandStr)可以调用执行cmd指令. cmd /c dir 是执行完dir命令后封闭命令窗口. cmd /k di ...
- (4.8)mysql备份还原——binlog查看工具之show binlog的使用
(4.8)mysql备份还原——binlog查看工具之mysqlbinlog及show binlog的使用 关键词:show binlog,mysql binlog查看,二进制文件查看,binlog查 ...
随机推荐
- QT学习篇: 入门(二)
库存订单界面: (1)包括序号.订单代码.订单名称.产品代码.产品类型.计划加工数量.最晚完工日期. (2)model增加临时map,用于存储库存订单. (3)后台计算完成后,会将库存订单推送给前台, ...
- 删除Excel中的打印预览留下的打印线
Excel 工作表打印后,会留有几条虚线打印线.如下图所示: 不少同学反映,他们尝试了很多操作却仍然无法消除.难道除了重新打开就没有别的办法了? 可以这样做: 在 Excel 2010 中,单 ...
- 初探react
知道这个框架有一段时间了,可是项目中没有用到,也懒得整理,最近两天比较清闲,又想起了它.好了,废话不多说了,都是干货. react是个什么框架? 为什么用react? react 的原理 react有 ...
- OpenStack JEOS 镜像
JEOS:Just Enough Operating System 维基百科地址:http://en.wikipedia.org/wiki/Just_enough_operating_system O ...
- C程序设计语言练习题1-19
练习1-19 编写函数reverse(s),将字符串s中的字符顺序颠倒过来.使用该函数编写一个程序,每次颠倒一个输入行中的字符顺序.代码如下: #include <stdio.h> // ...
- 使用开源word操作组件DocX的记录
1.DocX简介 1.1 简介 DocX是一个在不需要安装word的情况下对word进行操作的开源轻量级.net组件,是由爱尔兰的一个叫Cathal Coffey的博士生开发出来的.DocX使得操作w ...
- unity中的[xxxxxx]特性(Attributes)
[SerializeField] 在Inspector版面中显示非public属性,并且序列化:若写在public前面,等于没写. [Obsolete("调用提示信息")] [No ...
- Android的两种菜单
Android子菜单和选项菜单与上下文菜单的实现 菜单在Android开发中必不可少,可是要怎么实现各种菜单呢?是不是很头疼呢?下面我就来介绍一下: 1. 选项菜单和子菜单的实现 选项菜单:最常规的菜 ...
- MyBatis里字段到枚举类型的转换/映射
一.简介 我们在用MyBatis里,很多时间有这样一个需求:bean里有个属性是枚举,在DB存储时我们想存的枚举的代号,从DB拿出来时想直接映射成目标枚举类型,也即代号字段与Java枚举类的相互类型转 ...
- BZOJ3399: [Usaco2009 Mar]Sand Castle城堡
3399: [Usaco2009 Mar]Sand Castle城堡 Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 22 Solved: 17[Sub ...