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
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);
}
}
}
2 Comments
Ngoc Nam
I tried your solution, but it also exported Functions and Views, how can I ignore Functions and View in the exported result?
Ngoc Nam
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; ```