// 执行创建数据库操作

this.GetExecute(G_Con, "create database if not exists NEWDB");

this.sqlAddress = " -h " + IP + " -u" + User + " -p" + Password + " NEWDB ";

// 数据库的备份

private void btn_Dump_Click(object sender, EventArgs e)

{

using (SaveFileDialog sfd = new SaveFileDialog())

{

sfd.Filter = "数据库文件|*.sql";

sfd.FilterIndex = 0;

sfd.RestoreDirectory = true;

sfd.FileName = "BackUp" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".sql";

if (sfd.ShowDialog() == System.Windows.Forms.DialogResult.OK)

{

string filePath = sfd.FileName;

string cmd = "mysqldump " + sqlAddress + " > \"" + filePath + "\"";

string result = RunCmd(cmd);

if (result.Trim() == "")

{

MessageBox.Show("数据库备份成功!", "CMS", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

else

{

MessageBox.Show(result, "CMS", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}

}

}

//数据库的还原 // 还原数据库

private void btn_Import_Click(object sender, EventArgs e)

{

if (this.tb_Path.Text.Trim() == "")

{

MessageBox.Show("请选择要恢复的文件!", "CMS", MessageBoxButtons.OK, MessageBoxIcon.Information);

return;

}

//this.GetExecute(G_Con, "create database if not exists clothes");

string filePath = this.tb_Path.Text.Trim();

string cmd = "mysql " + sqlAddress + " < \"" + filePath + "\"";     string result = RunCmd(cmd);

if (result.Trim() == "")

{

MessageBox.Show("数据库恢复成功!", "CMS", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

else

{

MessageBox.Show(result, "CMS", MessageBoxButtons.OK, MessageBoxIcon.Information);

}

}

// 命令行操作

private string RunCmd(string command)

{

//例

Process     Process p = new Process();

p.StartInfo.FileName = "cmd.exe";      //确定程序名

p.StartInfo.Arguments = "/c " + command;    //确定程式命令行

p.StartInfo.UseShellExecute = false;        //Shell的使用

p.StartInfo.RedirectStandardInput = true;   //重定向输入

p.StartInfo.RedirectStandardOutput = true; //重定向输出

p.StartInfo.RedirectStandardError = true;   //重定向输出错误

p.StartInfo.CreateNoWindow = true;          //设置置不显示示窗口

p.Start();   //00

p.StandardInput.WriteLine(command);       //也可以用这种方式输入入要行的命令

p.StandardInput.WriteLine("exit");        //要得加上Exit要不然下一行程式

//p.WaitForExit();

//p.Close();

//return p.StandardOutput.ReadToEnd();

//输出出流取得命令行结果果

return p.StandardError.ReadToEnd();

}

C# MySQL数据库的备份 还原 初始化的更多相关文章

  1. C#中MySQL数据库的备份 还原 初始化

    直接在cmd执行如下代码: mysqldump -h localhost -uroot -p123 --default-character-set=utf8 --opt --disable-keys ...

  2. Mysql数据库之备份还原(mysqldump,LVM快照,select备份,xtrabackup)

    备份类型: 热备份:读写不受影响 温备份:仅可执行读备份 冷备份:离线备份,读写均不能执行,关机备份 物理备份和逻辑备份 物理备份:复制数据文件,速度快. 逻辑备份:将数据导出之文本文件中,必要时候, ...

  3. mysqldump工具实现mysql数据库的备份还原

    简介 冷.温.热备份 冷备:读写操作均不可进行 温备:读操作可执行:但写操作不可执行 热备:读写操作均可执行 MyISAM:温备,不支持热备 InnoDB:都支持 不管是热备还原还是冷备还原,还原时都 ...

  4. mysql数据库数据备份还原

    1.直接在命令行里面执行 备份一个数据库:mysqldump -h server -u username -p password db_name > database-sqlbkp_`date ...

  5. 如何用SQL语句实现Mysql数据库的备份与还原

    以前一直做android客户端的项目,根本没有开发asp.net mvc的开发,现阶段做了一个模块,参数设置,以及数据库的备份与还原.其需求如下: 参数设置 本项参数设置为对自动数据备份进行设置,管理 ...

  6. mysql数据库的备份和还原的总结

    mysql数据库的备份和还原的总结 (来自一运维同事的总结) 1. 备份方式: 热备:数据库在线进行备份,不影响读和写的在线备份方式! 温备:数据库在线进行备份,对表备份时先锁定写操作,仅可以执行读操 ...

  7. mysql数据库的备份和还原

    mysql数据库的备份命令:mysqldump -u root  -p 要备份的现有数据库名  >  备份后的sql文件名.sql,例如:  mysqldump -u root -p  heal ...

  8. [知了堂学习笔记]_Java代码实现MySQL数据库的备份与还原

    通常在MySQL数据库的备份和恢复的时候,多是采用在cmd中执行mysql命令来实现. 例如: mysqldump -h127.0.0.1 -uroot -ppass test > d:/tes ...

  9. Java代码实现MySQL数据库的备份与还原

    通常在MySQL数据库的备份和恢复的时候,多是采用在cmd中执行mysql命令来实现. 例如: mysqldump -h127.0.0.1 -uroot -ppass test > d:/tes ...

随机推荐

  1. android-读取Assets图片资源保存到SD - 随心

    public class ReadBitmap { public void readByte(Context c, String name, int indexInt) { byte[] b = nu ...

  2. R学习笔记

    把学习过程记载下来,加深印象,到时要是忘了也容易查,有需要的同学也可以参考: 1.包的安装:两种方法:一种通过R的菜单,先设定cran镜像,然后安装程序包,会出来一个列表,选择相应程序包安装,安装完毕 ...

  3. 具体解释EBS接口开发之物料导入API

    create_item inv_item_grp.create_item(p_commit => fnd_api.g_true, -- p_item_rec => l_item_rec, ...

  4. Model注解的后台原理

    Asp.net MVC的验证特性是由模型绑定器.模型元数据.模型验证器和模型状态组成的协调系统的一部分. 1.验证和模型绑定 默认情况下,Asp.net MVC框架在模型绑定石执行验证逻辑,在操作方法 ...

  5. HDU 5791 Two

    题意:给两个序列,求公共序列的个数 分析:很自然想到最长公共子序列的转移的转移形式,用dp[i][j]表示第一个串前i个 和第二个串前j个匹配的答案数量,a[i]==b[i],dp[i][j]=dp[ ...

  6. Letter of inquiry about employment possibilities, e-mail version

    Subject: (logical to recipient!) Inquiry about software engineering position after completion of M.S ...

  7. achartengine 实现平行线 动态数据 x轴动态移动

    achartengine做平行线的时候经常会遇到: java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1 at java.ut ...

  8. jdbc——CallableStatement,cst调用存储过程

    package CST对象调用存储过程; import java.sql.CallableStatement; import java.sql.Types; import org.junit.Test ...

  9. Java内存模型(转载)

    1. 概述 多任务和高并发是衡量一台计算机处理器的能力重要指标之一.一般衡量一个服务器性能的高低好坏,使用每秒事务处理数(Transactions Per Second,TPS)这个指标比较能说明问题 ...

  10. HDU 5740 - Glorious Brilliance

    题意: 给出已0 1染色的无向图(不一定联通),一次操作为一对相邻点颜色互换. 问使任意相邻点颜色不同,最少需要多少次操作 分析: 交换两点的代价即为两点间最短路. 故用BFS找出所有点到任意点的最短 ...