C#中MySQL数据库的备份 还原 初始化
直接在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数据库的备份 还原 初始化的更多相关文章
- C# MySQL数据库的备份 还原 初始化
// 执行创建数据库操作 this.GetExecute(G_Con, "create database if not exists NEWDB"); this.sqlAddres ...
- Mysql数据库之备份还原(mysqldump,LVM快照,select备份,xtrabackup)
备份类型: 热备份:读写不受影响 温备份:仅可执行读备份 冷备份:离线备份,读写均不能执行,关机备份 物理备份和逻辑备份 物理备份:复制数据文件,速度快. 逻辑备份:将数据导出之文本文件中,必要时候, ...
- mysqldump工具实现mysql数据库的备份还原
简介 冷.温.热备份 冷备:读写操作均不可进行 温备:读操作可执行:但写操作不可执行 热备:读写操作均可执行 MyISAM:温备,不支持热备 InnoDB:都支持 不管是热备还原还是冷备还原,还原时都 ...
- mysql数据库数据备份还原
1.直接在命令行里面执行 备份一个数据库:mysqldump -h server -u username -p password db_name > database-sqlbkp_`date ...
- 如何用SQL语句实现Mysql数据库的备份与还原
以前一直做android客户端的项目,根本没有开发asp.net mvc的开发,现阶段做了一个模块,参数设置,以及数据库的备份与还原.其需求如下: 参数设置 本项参数设置为对自动数据备份进行设置,管理 ...
- mysql数据库的备份和还原的总结
mysql数据库的备份和还原的总结 (来自一运维同事的总结) 1. 备份方式: 热备:数据库在线进行备份,不影响读和写的在线备份方式! 温备:数据库在线进行备份,对表备份时先锁定写操作,仅可以执行读操 ...
- [知了堂学习笔记]_Java代码实现MySQL数据库的备份与还原
通常在MySQL数据库的备份和恢复的时候,多是采用在cmd中执行mysql命令来实现. 例如: mysqldump -h127.0.0.1 -uroot -ppass test > d:/tes ...
- mysql数据库的备份和还原
mysql数据库的备份命令:mysqldump -u root -p 要备份的现有数据库名 > 备份后的sql文件名.sql,例如: mysqldump -u root -p heal ...
- 一、MySQL中的索引 二、MySQL中的函数 三、MySQL数据库的备份和恢复 四、数据库设计和优化(重点)
一.MySQL中的索引###<1>索引的概念 索引就是一种数据结构(高效获取数据),在mysql中以文件的方式存在.存储建立了索引列的地址或者指向. 文件 :(以某种数据 结构存放) 存放 ...
随机推荐
- 开发工具&环境
远程拷贝:scp cdh4.tar.gz root@10.239.44.111 ~ gerrit for code review: git add . git commit -a git push o ...
- .net平台下获取高精度时间类
原文:http://www.it118.org/specials/321869dd-98cb-431b-b6d2-82d973cd739d/d940a15c-0d36-4369-8de0-b07cf3 ...
- 【转载】Windows 7 不同安装模式简要区别(图解)
---------------------------------------------------------------------------------------------------- ...
- Qt 设计师手册
Qt设计师(Qt Designer)是使用Qt部件(Widgets)设计和使用图形用户界面(GUI)的工具.它允许我们以所见即所得的方式构建和定制自己的窗口(Windows)或对话框(Dialogs) ...
- JS --- 原型模式
创建一个对象,先来看一段代码: // 例如创建一个 Person 的构造函数, 让人有名字, 可以说话 function Person ( name ) { this.name = name; // ...
- JDBC + MySQL 示例
jdbc mysql connection 教程 翻译自:JDBC MySQL Connection Tutorial Java Database Connectivity (JDBC) 是一个基于J ...
- SQLite 事务
SQLite数据库是支持事务的,事务的特性可以保证让一系列的操作要么全部完成要么一个都不会完成. 一.调用SQLDatabase的beginTransaction()开起一个事务,当事务处理完成,调用 ...
- ROS学习笔记(四)——环境变量配置
1.查看环境变量配置情况,其实并没有什么卵用 $ export | grep ROS 或者用 $ printenv | grep ROS2.配置环境变量??$ source /opt/ros/indi ...
- 多线程学习中的Tips
ParameterizedThreadStart委托与ThreadStart委托,非常相似,但ParameterizedThreadStart委托是面向带参数方法的.注意ParameterizedTh ...
- Image放大缩小在放进Imageview
// 拿到要缩小放大的Bitmap obitmap = BitmapFactory.decodeResource(this.getResources(),R.drawable.ic_launcher) ...