C#程序备份数据库

 

namespace BackUpSql
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }


        //开始备份
        private void button2_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(textBox5.Text))
            {
                MessageBox.Show("请选择备份保存地址");
                return;
            }
            string host = textBox1.Text;
            string port = textBox2.Text;
            string user = textBox3.Text;
            string password = textBox4.Text;
            string database = textBox6.Text;
            string bakPath = textBox5.Text;
            if (string.IsNullOrEmpty(textBox1.Text)||string.IsNullOrEmpty(textBox2.Text)||string.IsNullOrEmpty(textBox3.Text)||string.IsNullOrEmpty(textBox4.Text)||string.IsNullOrEmpty(textBox6.Text))
            {
                MessageBox.Show("表单不能为空");
                return;
            }
            string cmdStr = "/c mysqldump -h" + host + " -P" + port + " -u" + user + " -p" + password + " " + database + " > " + bakPath;
            try
            {
                System.Diagnostics.Process.Start("cmd", cmdStr);
            }
            catch (Exception ex)
            {
               MessageBox.Show(ex.Message);
                return;
            }
        }

        //选择文件
        private void button1_Click(object sender, EventArgs e)
        {
            FolderBrowserDialog folderBrowserDialog = new FolderBrowserDialog();
            if (folderBrowserDialog.ShowDialog(this) == DialogResult.OK)
            {
                string FolderName = folderBrowserDialog.SelectedPath;
                textBox5.Text = FolderName+"\\"+DateTime.Now.ToString("yyyyMMddHHmmss")+".sql";
            }
        }
    }
}

相关推荐

  1. oracle 19c数据库联机备份与恢复

    2024-06-16 14:58:02       22 阅读
  2. 数据库备份与恢复

    2024-06-16 14:58:02       36 阅读
  3. linux中数据库备份

    2024-06-16 14:58:02       37 阅读
  4. mysql数据库备份命令

    2024-06-16 14:58:02       41 阅读
  5. mysql数据库备份恢复

    2024-06-16 14:58:02       22 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-06-16 14:58:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-06-16 14:58:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-06-16 14:58:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-06-16 14:58:02       20 阅读

热门阅读

  1. c语言回顾-结构体

    2024-06-16 14:58:02       6 阅读
  2. 牛客补题目

    2024-06-16 14:58:02       6 阅读
  3. RISC-V汇编总结

    2024-06-16 14:58:02       9 阅读
  4. 【LVGL v8.3】修改 ARC 控件指针图片风格

    2024-06-16 14:58:02       8 阅读
  5. 【机器学习】基于NeRF的3D动画渲染

    2024-06-16 14:58:02       6 阅读
  6. C#面:C#支持多重继承么?

    2024-06-16 14:58:02       5 阅读
  7. 简单游戏制作——飞行棋

    2024-06-16 14:58:02       8 阅读
  8. FPGA NET

    FPGA NET

    2024-06-16 14:58:02      8 阅读
  9. mac m芯片安装win11遇坑

    2024-06-16 14:58:02       7 阅读