直接在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. 伪共享和缓存行填充,从Java 6, Java 7 到Java 8

    关于伪共享的文章已经很多了,对于多线程编程来说,特别是多线程处理列表和数组的时候,要非常注意伪共享的问题.否则不仅无法发挥多线程的优势,还可能比单线程性能还差.随着JAVA版本的更新,再各个版本上减少 ...

  2. ssh远程执行命令

    ssh -p $port $user@$p 'cmd' $port : ssh连接端口号 $user: ssh连接用户名 $ip:ssh连接的ip地址 cmd:远程服务器需要执行的操作 ssh -p ...

  3. 怎样处理“error C2220: warning treated as error - no object file generated”错误

    最近用VS2010 编译ceflib开源库是出现"怎样处理"error C2220: warning treated as error - no object file gener ...

  4. 新项目CRM(1)

    <title>CRM登陆</title> <script type="text/javascript"> if (window.parent.w ...

  5. Android Studio 2.0使用指南

    一.下载界面.[无激活码 无序列码 无毒请放心使用][需将JAVA程序升级到1.8] 网址:http://www.android-studio.org/index.php/download/andro ...

  6. SQL 已有数据的表创建标识列

    针对已有数据的表创建标识列: ,) constraint FID_1 primary key(FID)

  7. 关于url中的#-----hash

    前言:不知道你们对url地址中的#一开始是怎么理解的,反正我以前一直都是默认那就是本页面中该id的位置.今天看了篇文章,才把这个真正透彻理解. 1,#涵义 #代表网页中的一个位置.其右面的字符,就是该 ...

  8. WinForm中MouseEnter和MouseLeave混乱的问题

    MouseEnter+MouseLeave不行,我用了MouseMove+MouseLeave,效果一样 最近做个聊天的系统,仿照qq的界面设计,像qq聊天界面中字体.表情.截图等图片,鼠标放上去显示 ...

  9. 24. Swap Nodes in Pairs

    24. Swap Nodes in Pairs Given a linked list, swap every two adjacent nodes and return its head. For ...

  10. python & c

    http://www.ibm.com/developerworks/cn/linux/l-cn-pythonandc/