[英]mysqldump.exe not taking full backup of mysql database
我有一個備份MySQL數據庫的程序。我也有不同的MySQL服務器。 此過程適用於某些MySQL服務器。但在某些服務器上,它將無法正常工作並創建大小為1kb的備份文件。
public void DatabaseBackup(string ExeLocation, string DBName)
{
try
{
string tmestr = "";
tmestr = DBName + "-" + DateTime.Now.ToString("hh.mm.ss.ffffff") + ".sql";
tmestr = tmestr.Replace("/", "-");
tmestr = "c:/" + tmestr;
StreamWriter file = new StreamWriter(tmestr);
ProcessStartInfo proc = new ProcessStartInfo();
string cmd = string.Format(@"-u{0} -p{1} -h{2} {3}", "uid", "pass", "host", DBName);
proc.FileName = ExeLocation;
proc.RedirectStandardInput = false;
proc.RedirectStandardOutput = true;
proc.Arguments = cmd;
proc.UseShellExecute = false;
proc.CreateNoWindow = true;
Process p = Process.Start(proc);
string res;
res = p.StandardOutput.ReadToEnd();
file.WriteLine(res);
p.WaitForExit();
file.Close();
}
catch (IOException ex)
{
}
}
任何人都可以告訴我這是什么問題,我該如何解決它。
最后我得到了答案。 我們需要對我們想要備份的MySQL用戶或數據庫的SELECT和LOCK_TABLE特權。 在數據庫上設置這些權限后,我可以對該數據庫進行完全備份。
備份聲明在哪里?
以下是備份數據庫的最佳方法:
private void BackupDatabase()
{
string time = DateTime.Now.ToString("dd-MM-yyyy");
string savePath = AppDomain.CurrentDomain.BaseDirectory + @"Backups\"+time+"_"+saveFileDialogBackUp.FileName;
if (saveFileDialogBackUp.ShowDialog() == DialogResult.OK)
{
try {
using (Process mySqlDump = new Process())
{
mySqlDump.StartInfo.FileName = @"mysqldump.exe";
mySqlDump.StartInfo.UseShellExecute = false;
mySqlDump.StartInfo.Arguments = @"-u" + user + " -p" + pwd + " -h" + server + " " + database + " -r \"" + savePath + "\"";
mySqlDump.StartInfo.RedirectStandardInput = false;
mySqlDump.StartInfo.RedirectStandardOutput = false;
mySqlDump.StartInfo.CreateNoWindow = true;
mySqlDump.Start();
mySqlDump.WaitForExit();
mySqlDump.Close();
}
}
catch (IOException ex)
{
MessageBox.Show("Connot backup database! \n\n" + ex);
}
MessageBox.Show("Done! database backuped!", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
祝好運!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.