// 执行创建数据库操作

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. C程序设计语言(K&R)笔记

    1.表达式中float类型的操作数不会自动转换为double类型.一般来说,数学函数(如math.h)使用双精度类型的变量.使用float类型主要是为了在使用较大数组时节省存储空间,有时也为了节省机器 ...

  2. LR实战之Discuz开源论坛——登录场景设计

    以下是根据个人项目经验,对登录场景的设计,如下步骤: 一.打开Controller,添加登录脚本,选择“手动场景”,一般我们项目中经常使用的是“手动场景”类型设计,如图 二.在“设计”部分,设置场景的 ...

  3. PHP: configure: error: mysql configure failed. Please check config.log for more information.

    为php增加mysql模块时报错 configure: error: mysql configure failed. Please check config.log for more informat ...

  4. js 写日期

    <SCRIPT language="JavaScript" type="text/JavaScript">   today = new Date() ...

  5. Android使用NumberPicker控件实现选择城市,生日

    本人菜鸟一枚,第一次写技术博客,有点小紧张,加上代码很乱,求不喷. 先放效果图: 界面就这么简单. 然后放上代码: package com.example.dialog; import java.ut ...

  6. js页面换行与空格

    1.换行 +'<br/>\n': 2.空格 1#JS——输出内容document.write#用于直接向 HTML 输出流写内容.简单的说就是直接在网页中输出内容.1.输出内容用“”括起, ...

  7. Sql Server获得每个表的行数

    SELECT o.[name], ddps.[row_count] FROM sys.indexes AS i INNER JOIN sys.objects AS o ON i.[object_id] ...

  8. golang Date format

    package main import ( "fmt" "time" ) // @link https://golang.org/pkg/time/ func ...

  9. CentOS6.4 LAMP环境搭建

    网上的教程,不能按着抄打进去,这样会打乱你环境放置位置, 会导致配置路径会出问题. 要有一个环境目录优化, 把环境文件都装在/usr/local里面 首先,把安装文件rar都放置在/usr/local ...

  10. 安装eclipse

    前提,安装好jdk并成功配置好环境变量 下载eclipse-standard-kepler-R-win32-x86_64,直接打开里面的eclipse.exe文件即可