Skip to content

MySqlBackupNET/MySqlBackup.Net

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

MySqlBackup.NET

A versatile tool for backing up and restoring MySQL databases in C#, VB.NET, and ASP.NET.

Latest Release: v2.3.9 (March 13, 2025)
Change Log


Overview

MySqlBackup.NET is a .NET library (DLL) designed to backup and restore MySQL databases. Compatible with multiple MySQL connectors—MySql.Data.DLL, MySqlConnector.DLL, and Devart.Express.MySql.DLL—it offers a programmatic alternative to tools like MySqlDump, providing greater control and flexibility in .NET environments.

Developed in C#, this library supports any .NET language (e.g., VB.NET, F#) and excels in scenarios where MySqlDump.exe or MySQL Workbench are impractical, such as web-based applications (ASP.NET) or end-user tools with simplified interfaces.


Key Features

  • Backup and restore MySQL databases programmatically.
  • Supports all .NET languages.
  • Export/import via files or MemoryStream.
  • Conditional row exports (filter tables/rows).
  • Progress reporting for export and import tasks.
  • Flexible row export modes: INSERT, INSERT IGNORE, REPLACE, ON DUPLICATE KEY UPDATE, UPDATE.
  • Ideal for ASP.NET and web service integration.

Getting Started

Installation

Download

Grab the latest release from: GitHub Releases

NuGet Packages

Install via NuGet Package Manager:

Add to Your Project

See the detailed guide:
How to Add This Library into Your Project


Basic Usage

Backup a Database

string connString = "server=localhost;user=root;pwd=qwerty;database=test;";
string filePath = @"C:\backup.sql";

using (var conn = new MySqlConnection(connString))
{
    using (var cmd = new MySqlCommand())
    {
        using (var mb = new MySqlBackup(cmd))
        {
            cmd.Connection = conn;
            conn.Open();
            mb.ExportToFile(filePath);
            conn.Close();
        }
    }
}

Restore a Database

string connString = "server=localhost;user=root;pwd=qwerty;database=test;";
string filePath = @"C:\backup.sql";

using (var conn = new MySqlConnection(connString))
{
    using (var cmd = new MySqlCommand())
    {
        using (var mb = new MySqlBackup(cmd))
        {
            cmd.Connection = conn;
            conn.Open();
            mb.ImportFromFile(filePath);
            conn.Close();
        }
    }
}

Why MySqlBackup.NET?

Unlike MySQL Workbench (developer-focused) or MySqlDump.exe (restricted in web environments), MySqlBackup.NET offers:

  • End-User Simplicity: Preset parameters for a one-click backup experience.
  • Web Compatibility: Runs seamlessly in ASP.NET, bypassing hosting restrictions on executables.
  • Programmatic Control: Fine-tuned output handling within .NET.

Dependencies

MySqlBackup.NET requires one of these MySQL connectors:

Connector Source License DLLs
MySqlConnector MySqlConnector MIT MySqlConnector.dll
MySql.Data MySQL Connector/Net GPL MySql.Data.dll
Devart Express dotConnect for MySQL Custom (FAQ) Devart.Data.dll, Devart.Data.MySql.dll

Configuration Tips

Unicode Support

For databases with UTF-8 or Unicode characters (e.g., À, Ñ, Cyrillic, Chinese), use:

server=localhost;user=root;pwd=qwerty;charset=utf8;

Or, for broader support:

server=localhost;user=root;pwd=qwerty;charset=utf8mb4;

DateTime Handling (MySql.Data Only)

To avoid conversion errors with null or date-only values, add:

server=localhost;user=root;pwd=qwerty;charset=utf8;convertzerodatetime=true;

Performance Benchmark

Compare MySqlBackup.NET to MySqlDump for a 3.5GB database (15M rows):

Task Tool Time File Size
Backup MySqlDump ~2m 35s 4.66 GB
Backup MySqlBackup.NET ~7m 48s 4.59 GB
Restore MySql.exe ~8m 41s -
Restore MySqlBackup.NET ~9m 41s -

Full details: Performance Benchmark Wiki


Additional Tools

Backup All Databases
Export all databases to separate SQL files with this sub-project:
MySqlBackup_All_DB


License

MySqlBackup.NET is released under The Unlicense, making it free for any use.


Conclusion

MySqlBackup.NET empowers developers and end-users alike with a robust, .NET-native solution for MySQL database management. Whether for desktop apps, web services, or automated backups, it’s a versatile addition to your toolkit.

Explore more on GitHub!