How to execute backup of large database of mysql server

穿精又带淫゛_ 提交于 2019-12-25 15:32:23

问题


I'm creating a web application. And in that application i need to take backup of many MySQL databases.

For that i created an option it works fine on small databases but troughs exception Out of memory exception for large databases.

Note:- There is enough disc space available on both web server and database server.

And also some time it works very fine and some time it creates 1 kb size of backup files.

Backup procedure

public static string DatabaseBackup(string ExeLocation,
    string DBName,
    string Ip,
    string Uid,
    string Pass,
    string FileNm)
{
    string status = "";
    try
    {
        StreamWriter file = new StreamWriter(FileNm);
        ProcessStartInfo proc = new ProcessStartInfo();
        string cmd = string.Format(@"-u{0} -p{1} -h{2} {3}", Uid, Pass, Ip, 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();
        status = "OK";
    }
    catch (Exception ex)
    {
        status = ex.Message;
    }
    return status;
}

Can any one help me what is wrong and how can i solve both problems.


回答1:


if the file you are reading it's bigger then your available memory an exception will be thrown. check in this article how to process large files and how to prevent out of memory exception C# FileStream : Optimal buffer size for writing large files?



来源:https://stackoverflow.com/questions/19583564/how-to-execute-backup-of-large-database-of-mysql-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!