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#?
Asked
Active
Viewed 3,595 times
1 Answers
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);
}
}
}

LoRdPMN
- 512
- 1
- 5
- 18
-
I tried your solution, but it also exported Functions and Views, how can I ignore Functions and View in the exported result? – Ngoc Nam Oct 29 '18 at 01:01
-
1I 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; ``` – Ngoc Nam Oct 29 '18 at 01:24