Skip to content
David Kittell
David Kittell

Application & System: Development / Integration / Orchestration

  • Services
    • Application Development
    • Online Application Integration
  • Code
  • Online Tools
  • Tech Support
David Kittell

Application & System: Development / Integration / Orchestration

C# Backup and Restore MySQL Database(s)

Posted on April 6, 2014October 26, 2015 By David Kittell

Must Download DLLs from http://mysqlbackupnet.codeplex.com/

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

namespace MySQLBackupRestore
	{
	public partial class Form1 : Form
		{
		public static string sMySQLServer = "192.168.43.1";
		public static string sMySQLUser = "root";
		public static string sMySQLPassword = "";

		public Form1 ()
			{
			InitializeComponent();
			}

		private void btnRestore_Click (object sender, EventArgs e)
			{

			}

		private void btnBackup_Click (object sender, EventArgs e)
			{
			Backup("mysql", "C:tempbackup.sql");
			}

		private void Backup (string sMySQLDatabase, string sFilePath)
			{
			string constring = "server=" + sMySQLServer + ";user=" + sMySQLUser + ";pwd=" + sMySQLPassword + ";database=" + sMySQLDatabase + ";";
			//string file = "C:tempbackup.sql";
			using (MySqlConnection conn = new MySqlConnection(constring))
				{
				using (MySqlCommand cmd = new MySqlCommand())
					{
					using (MySqlBackup mb = new MySqlBackup(cmd))
						{
						cmd.Connection = conn;
						conn.Open();
						mb.ExportToFile(sFilePath);
						conn.Close();
						}
					}
				}
			}

		private void Restore (string sMySQLDatabase, string sFilePath)
			{
			string constring = "server=" + sMySQLServer + ";user=" + sMySQLUser + ";pwd=" + sMySQLPassword + ";database=" + sMySQLDatabase + ";";
			//string file = "C:tempbackup.sql";
			using (MySqlConnection conn = new MySqlConnection(constring))
				{
				using (MySqlCommand cmd = new MySqlCommand())
					{
					using (MySqlBackup mb = new MySqlBackup(cmd))
						{
						cmd.Connection = conn;
						conn.Open();
						mb.ImportFromFile(sFilePath);
						conn.Close();
						}
					}
				}
			}
		}
	}
Originally Posted on April 6, 2014
Last Updated on October 26, 2015
All information on this site is shared with the intention to help. Before any source code or program is ran on a production (non-development) system it is suggested you test it and fully understand what it is doing not just what it appears it is doing. I accept no responsibility for any damage you may do with this code.

Related

C# Project Code CSharp MySQL SQL

Post navigation

Previous post
Next post

Related Posts

MySQL Procedure Get WordPress Site Name

Posted on October 13, 2015October 13, 2015

If you manage many WordPress site databases it can get a bit crazy to know which site goes with what database but it gets more “fun” when you have a network site, below I attempt to help document some ways to help. This first example is a rather long process…

Read More

Flash Video

Posted on September 3, 2013October 26, 2015

<script language="JavaScript" type="text/javascript"> // <![CDATA[ var fo = new FlashObject("../flash/videoPlayer.swf", "foo", "455","400", "8.0.22", "#ffffff", true); fo.addParam("wmode", "transparent"); fo.addParam("quality","high"); fo.addParam("align","middle"); fo.addParam("salign",""); fo.addParam("scale","noscale"); fo.addParam("allowScriptAccess","sameDomain"); //flash vars that need to be passed into the flash movie … fo.addVariable(‘userId’, ‘public’); fo.addVariable(‘videoId’, ‘HealthClips/hc_ca_00053_en’); fo.addVariable(‘skinName’,’../flash/haloSkin_1.swf’); fo.addVariable(‘bufferTime’, ‘3’); fo.addVariable(‘autoRewind’, ‘true’); fo.addVariable("autoPlay", "true"); fo.addVariable(‘streamId’, ‘HealthClips/hc_ca_00053_en’); fo.write("flashcontent"); // ]]>…

Read More

HTML5 Geolocation

Posted on November 5, 2013October 26, 2015

[raw] Click the button to get your coordinates: Try It [/raw] <!DOCTYPE html> <html> <body> <p id="demo">Click the button to get your coordinates:</p> <button onclick="getLocation()">Try It</button> <script> var x=document.getElementById("demo"); function getLocation() { if (navigator.geolocation) { navigator.geolocation.getCurrentPosition(showPosition); } else{x.innerHTML="Geolocation is not supported by this browser.";} } function showPosition(position) { x.innerHTML="Latitude: "…

Read More

Code

Top Posts & Pages

  • PowerShell - Rename Pictures to Image Taken
  • Front Page
  • PowerShell - IIS Remove Site
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories

Recent Posts

  • Javascript – Digital Clock with Style
  • BASH – Web Ping Log
  • BASH – Picture / Video File Name Manipulation
  • Mac OSX Terminal – Create SSH Key
  • Bash – Rename Picture

Top Posts

  • PowerShell - Rename Pictures to Image Taken
  • PowerShell - IIS Remove Site
  • SQLite - Auto-Increment / Auto Generate GUID
  • PowerShell - FTP Upload Directory With Sub-Directories
  • Raspberry Pi - Remove Default Apps
  • PowerShell - Change Windows CD/DVD Drive Letter
©2025 David Kittell | WordPress Theme by SuperbThemes