Questions tagged [mysqlbackup.net]

A .NET Framework library used for backup, export, restore, import of MySql database. An alternative for MySqlDump.exe. Written in C#. Can be used in VB.NET and ASP.NET.

MySqlBackup.NET is an open source project used as alternative to MySqlDump and MySql WorkBench for exporting and importing (backup & restore) of MySQL database in .NET environment.

Project Site: https://github.com/MySqlBackupNET/MySqlBackup.Net

Nuget:

PM> Install-Package MySqlBackup.NET

MySql Workbench 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 Workbench as a backup tool is not a suitable solution for client or end-user.

On the other hand, MySqlDump.exe cannot be executed directly from the Web Server. As most providers forbid that, MySqlBackup will be helpful in building a web-based (ASP.NET) backup tool.

Prerequisite / Dependencies

MySqlBackup.NET is built on top of MySQL dot net Connector/Net (MySql.Data.DLL). A reference of this DLL must be added into your project in order for MySqlBackup.NET to work. MySql.Data.DLL is developed by Oracle Corporation, licensed under GPL License (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html).

A Quick Example of Backup/Exporting MySql Database:

string constring = "server=localhost;user=root;pwd=qwerty;database=test;";

// Important Additional Connection Options
constring += "charset=utf8;convertzerodatetime=true;";

string file = "C:\\backup.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(file);
            conn.Close();
        }
    }
}

A Quick Example of Restore/Importing MySql Database:

string constring = "server=localhost;user=root;pwd=qwerty;database=test;";

// Important Additional Connection Options
constring += "charset=utf8;convertzerodatetime=true;";

string file = "C:\\backup.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(file);
            conn.Close();
        }
    }
}

Reminder 1

MySqlBackup.NET stands on top of MySql.Data.DLL which also stands on top of .NET Framework, which uses UTF8 encoding by default. If your database involves any UTF8 or Unicode Characters. You must use a MySQL database with default character of UTF8 while handling Unicode Characters, such as

  • Western European specific languages, the character of 'À', 'ë', 'õ', 'Ñ'.
  • Russian, Hebrew, India, Arabic, Chinese, Korean, Japanese characters, etc.

You are recommended to apply the connection string option of charset=utf8. Example:

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

Reminder 2

DateTime conversion between MySQL and .NET Framework. In MySQL, there are various of DateTime format, such as null value or Date only data. But, in .NET Framework, there is no null value (or Date only) for DateTime. A data conversion error (exception) will be thrown. This error is not caused by MySqlBackup.Net. MySql.Data.DLL is designed to throw this exception of data conversion error. Therefore, a connection string option of convertzerodatetime=true is strongly recommended to be applied. Example:

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

For more reminders and support, please visit the Wiki page of the project site.

8 questions
3
votes
2 answers

Cannot restore mysql dump file with mysql.exe in C#

I have created the mysql database dump file(utf8) successfully with this: ProcessStartInfo psi = new ProcessStartInfo(); psi.FileName = Application.StartupPath + "\\mysqldump.exe"; psi.RedirectStandardInput = false; psi.RedirectStandardOutput =…
mjb
  • 7,649
  • 8
  • 44
  • 60
3
votes
1 answer

How to backup specific MySQL table using C#

I have been doing backup of MySQL tables using MySqlBackup.dll in C#. I have no idea on how to backup specific table inside a MySQL schema. How can I backup only one or two specific tables using C#?
ThEpRoGrAmMiNgNoOb
  • 1,256
  • 3
  • 23
  • 46
3
votes
1 answer

Exception when using MySqlBackup.NET to export database

I used the following code for backup the MYSQL database. private void button2_Click(object sender, EventArgs e) { string file = "D:\\backup.sql"; //string conn = "server=localhost;user=root;pwd=qwerty;database=test;"; …
Shashika
  • 219
  • 1
  • 6
  • 18
1
vote
1 answer

MySqlBackup.NET issue with MySql.Data version

I have one winforms application which uses MySQL as database. I was using the package MySqlBackup.NET to perform backup tasks in the application. Now I updated the MySQL connector to version 8.0.17 and the MySqlBackup.NET to version 2.3.0, which are…
user1620696
  • 10,825
  • 13
  • 60
  • 81
0
votes
1 answer

Create table/view without checking if referred table/view exists

I have a MySql Database connected to a VB.Net application. All I want is to create the database automatically using my application. I currently use MySqlBackup.Net available in NuGet Packages to accomplish the task. The method I use to…
0
votes
1 answer

Backup MariaDB database from Android client (Xamarin)

MySQLBackup.net works fine on Windows applications, but not in Xamarin (tested with exact same code). Is there any workaround or alternatives that I can use ? I'm really lost... I want to backup my database from a Linux (Debian9) MariaDB server, so…
0
votes
0 answers

Convert decrypt file in php from vb.net

How to Decrypt this file in php . using MySqlBackup.net library in vb.net project. help me to solve or provide valid solution. Dim filePath As String = Path.GetDirectoryName(Application.ExecutablePath) & "\" Dim constring As String =…
user8405290
0
votes
1 answer

MySqlBackup.NET QueryExpress.ExecuteScalarStr() outputs strings enclosed in double-quotes instead of backticks

I'm using MySqlBackup.dll (MySqlBackup.NET) which in turn uses MySql.Data.dll to dump the database. I thought MySqlBackup.NET was causing this behavior, so I took it out of the equation. If I run this code in my solution: Dim cmd = New…
andypopa
  • 536
  • 6
  • 15