3

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 Answer 1

5

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);
        }
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

I tried your solution, but it also exported Functions and Views, how can I ignore Functions and View in the exported result?
I have to set those attributes to be false ``` mb.ExportInfo.ExportFunctions = false; mb.ExportInfo.ExportViews = false; mb.ExportInfo.ExportTriggers = false; mb.ExportInfo.ExportEvents = false; mb.ExportInfo.ExportProcedures = false; mb.ExportInfo.ExportRoutinesWithoutDefiner = false; ```

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.