How To Backup MySql Database


1.Create folder in D drive (folder name = blog ) 

2.Create Application

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

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

        private void button1_Click(object sender, EventArgs e)
        {
            string conn = "server=localhost;user=root;password=;database=blog;charset=utf8";

            string file = " D:\\blog\\blog.sql";
            using (MySqlConnection con = new MySqlConnection(conn))
            {
                using (MySqlCommand cmd = new MySqlCommand())
                {
                    using (MySqlBackup mb = new MySqlBackup(cmd))
                    {
                        cmd.Connection = con;
                        con.Open();
                        mb.ExportToFile(file);
                        con.Close();
                    }
                }
            }
            MessageBox.Show("Backup Complete...!");
        }
    }
}

output




Comments

Popular posts from this blog

C# Analog Clock

Basic Prolog (List)

SOLID Principles