Project Description
A programming tool to backup and restore of MySQL database in C#/VB.NET/ASP.NET and supports Unicode/UTF8 characters.

Online Demo: http://mysqlbackup.somee.com/

Backup a MySQL Database

C#

string file = "C:\\backup.sql";
string conn = "server=localhost;user=root;pwd=qwerty;database=test;";
MySqlBackup mb = new MySqlBackup(conn);
mb.ExportInfo.FileName = file;
mb.Export();}

VB.NET

Dim con As String = "server=localhost;user=root;pwd=1234;database=test;"
Dim file As String = "C:\backup.sql"
Dim mb As New MySqlBackup(con)
mb.ExportInfo.FileName = file
mb.Export()

Restore a MySQL Database

C#

string file = "C:\\backup.sql";
string conn = "server=localhost;user=root;pwd=qwerty;database=test;";
MySqlBackup mb = new MySqlBackup(conn);
mb.ImportInfo.FileName = file;
mb.Import(file);

VB.NET

Dim con As String = "server=localhost;user=root;pwd=1234;database=test;"
Dim file As String = "C:\backup.sql"
Dim mb As New MySqlBackup(con)
mb.ImportInfo.FileName = file
mb.Import()

Introduction

MySqlBackup.NET is a tool (DLL) that can backup/restore MySQL database in .NET Programming Language. It is an alternative to MySqlDump. This tool uses native .NET language to handle all values and parameters, therefore it can handle Unicode/UTF8 character (multi-language) well.

This tool is develop in C# but useable in VB.NET.

Another benefits of making this tool is, we don't have to rely on two small programs - MySqlDump.exe and MySql.exe to perform the backup and restore task. We will have better control on the output result.

The most common way to backup a MySQL Database is by using MySqlDump and MySQL Administrator.

MySQL Administrator is good for developers, but, when comes to client or end-user, the recommended way is to get every parameter preset and all they need to know is press the big button "Backup" and everything is done. Using MySQL Administrator as a backup tool is not a suitable solution for client or end-user.

On the other hand, MySqlDump is another tool that can customize within code to meet specific situation. However, MySqlDump has compatible problems while handling with Unicode characters, for example Korean, Japanese, Chinese and Russian characters. The data will corrupt during the encoding between MySQL database and MySqlDump. Besides, MySqlDump cannot be used for Web applications. As most providers forbid that, MySqlBackup will be helpful in building a web-based (ASP.NET) backup tool. 

Aims

  • As a tool that integrated directly into .NET applications to Backup and Restore MySql Database.
  • Support Multi-Language Character. (UTF8)
  • Customizable Backup/Restore behaviour.
  • Stable, Error Free, Easy to use

Features

  • Export/Import Table's Structures & Rows
  • Export/Import Stored Procedures, Functions, Triggers, Events, Views
  • Custom Tables and Rows Export
  • Able to apply encryption to the process
  • Export BLOB and save as files
  • Gather SQL Syntax errors during Import process
  • Export/Import will report progress. Enable the usage of progress bar
  • Able to execute in Synchronous or Asynchronous mode.
  • Export/Import To/From Zip File.

Limitation

Cannot handle multiple MEDIUMTEXT and MEDIUMBLOB data type. (some where more than 18MB length in single SQL query)

Multiple MEDIUMTEXT and MEDIUMBLOB will make (a single SQL) System.String and MySqlCommand.CommandText long enough to cause System.OutOfMemoryException.

This is not limited by the number of rows. MySqlBackup.NET can backup & restore millions of rows.

However, one thing for sure is, if the length of SQL can be inserted into MySQL database by any .NET application, MySqlBackup.NET is able to do so. Conversely, if you can't insert the SQL (because of the length) by any .NET apps, MySqlBackup.NET too can't.

If the user used in the MySql Connection has super privilege, then MySqlBackup.NET will set the max_allowed_packet to 1GB, which is the maximum length of single query of MySQL. 

MySqlBackup.NET is currently not able to backup & restore LONGBLOB and LONGTEXT data type.

It is somehow wondering that:

The computer has 4GB of RAM and there are still 2.5GB free, why the software still raise the exception telling that it is Out Of Memory?  

After some findings, 1 of the useful information may describe the problem:

Maybe there are some techniques out there that can tweaks the memory handling which allow a System.String able to hold a length of data up to 1GB. 

Or maybe, there is another method to replace this. However, this is still under investigation. 

Other Resources

Nuget.org:

(Note: It is available, but not updated to the latest version yet) You can find this product in nuget.org: https://nuget.org/packages/MySqlBackup.NET/   or install in package Manager Console: 

PM> Install-Package MySqlBackup.NET

www.ohloh.net: https://www.ohloh.net/p/MySqlBackupNET

www.codeproject.com: http://www.codeproject.com/Articles/256466/MySqlBackup-NET-MySQL-Backup-Solution-for-Csharp-V

Joining the Project

You are welcome to improve / extend the functionality, stability and efficiency of the project.

Documentation writings are welcome too.

Last edited Jan 24 at 7:30 AM by adriancs, version 45