How to backup specific MySQL table using C#

3.7k views Asked by At

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#?

1

There are 1 answers

2
LoRdPMN On BEST ANSWER

According to this documentation section, you can specify it in the MySqlBackup.ExportInfo using the List<string> property called TablesToBeExportedList.

So, something like this should work:

string constring = "server=localhost;user=root;pwd=1234;database=test1;";
string file = "Y:\\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.ExportInfo.TablesToBeExportedList = new List<string> {
                "Table1",
                "Table2"
            };
            mb.ExportToFile(file);
        }
    }
}