private void exportDBToolStripMenuItem_Click(object sender, EventArgs e) { using (var db = new Model1()) { string constring = db.GetConfigConString(); string file = Path.Combine(Application.StartupPath, "backup.sql"); if (File.Exists(file)) { File.Delete(file); } 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(); } } } var sql = File.ReadAllText(file); sql = sql.Replace("INSERT INTO", "REPLACE INTO"); File.WriteAllText(file, sql); MessageBox.Show("Backup done."); } }