直接在cmd执行如下代码:
mysqldump  -h localhost -uroot -p123 --default-character-set=utf8 --opt --disable-keys --lock-all-tables -R --hex-blob  TEST >D:\PM\bin\Debug\BackUp\TEST_20161212.sql

TEST为数据库名称

// 执行创建数据库操作
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 = ;
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(); // 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数据库的备份 还原 初始化

    // 执行创建数据库操作 this.GetExecute(G_Con, "create database if not exists NEWDB"); this.sqlAddres ...

  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. [知了堂学习笔记]_Java代码实现MySQL数据库的备份与还原

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

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

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

  9. 一、MySQL中的索引 二、MySQL中的函数 三、MySQL数据库的备份和恢复 四、数据库设计和优化(重点)

    一.MySQL中的索引###<1>索引的概念 索引就是一种数据结构(高效获取数据),在mysql中以文件的方式存在.存储建立了索引列的地址或者指向. 文件 :(以某种数据 结构存放) 存放 ...

随机推荐

  1. BCP 导出导入数据(SQL Server)

    BCP指令工具可通过安装SQL Server获得. 1. 根据现有的数据库生成表的format文件(导入导出数据的时候需要) bcp db_test.dbo.Table1 format nul -c ...

  2. ADO 读取 ACCESS

    #pragma once #include <vector> // 加入ADO支持库, #import "C:\Program Files\Common Files\System ...

  3. NPOI 教程 - 2.1单元格合并

    来源:http://liyingchun343333.blog.163.com/blog/static/3579731620091018212990/ 合并单元格在制作表格时很有用,比如说表格的标题就 ...

  4. 模板——Tarjan

    #include <cstdio> #include <cstring> #include <iostream> #include <vector> u ...

  5. PHPCMS企业站制作

    安装 将下载好的文件放到www目录下 地址栏中输入 http://localhost:8080/phpcms/install_package/install 打开安装页面 进行安装即可. 如果出现: ...

  6. javascriptの循序渐进(一)

    javascriptの循序渐进系列为<javascript高级程序设计>的读书笔记,记录了看书过程中觉得重点的地方和一些总结,为学习javascript打好基础. ------------ ...

  7. Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法总结

    本文对Jquery中$.get(),$.post(),$.ajax(),$.getJSON()的用法进行了详细的总结,需要的朋友可以参考下,希望对大家有所帮助. 详细解读Jquery各Ajax函数:  ...

  8. 关于C语言结构体,指针,声明的详细讲解。——Arvin

    关于结构体的详细分析 只定义结构体 struct Student { int age; char* name; char sex;//结构体成员 };//(不要忘记分号) Student是结构体的名字 ...

  9. C# 利用NPOI 实现Excel转html

    public void ExcelToHtml(string fileName, IWorkbook workbook) { ExcelToHtmlConverter excelToHtmlConve ...

  10. viewPager 的可滑动 Title

    有三种方式: 1. 系统提供的title 缺点:标题在viewpager的滑动过程中也会滑动 实现:在ViewPager布局中添加 PagerTabStrip 或者是 PagerTitleStrip ...