简体   繁体   English

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

[英]mysqldump.exe not taking full backup of mysql database

I have a procedure for backing up MySQL database.And also i have different MySQL servers. 我有一个备份MySQL数据库的程序。我也有不同的MySQL服务器。 This procedure works on some of MySQL servers.But on some of servers it won't works proper and create a backup file with the size of 1kb. 此过程适用于某些MySQL服务器。但在某些服务器上,它将无法正常工作并创建大小为1kb的备份文件。

Code

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)
    {

    }
}

Can any one tell me what is the problem and how can i solve it. 任何人都可以告诉我这是什么问题,我该如何解决它。

Finally i got the answer. 最后我得到了答案。 We need SELECT and LOCK_TABLE privilege on MySQL user or database on which we want backup. 我们需要对我们想要备份的MySQL用户或数据库的SELECT和LOCK_TABLE特权。 After setting these privilege on database i am able to take full backup of that database. 在数据库上设置这些权限后,我可以对该数据库进行完全备份。

Where is the Backup Statement? 备份声明在哪里?

Here is the best way to backup your database : 以下是备份数据库的最佳方法:

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);
            }
        }

Good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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