繁体   English   中英

mysqldump.exe没有完全备份mysql数据库

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM