备份mysql数据库时发生异常 [英] exception while taking mysql database back up

查看:92
本文介绍了备份mysql数据库时发生异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我使用此代码备份了mysql

Hi all
I used this code for taking mysql back up

try
        {
            DateTime Time = DateTime.Now;
            int year = Time.Year;
            int month = Time.Month;
            int day = Time.Day;
            int hour = Time.Hour;
            int minute = Time.Minute;
            int second = Time.Second;
            int millisecond = Time.Millisecond;

            //Save file to C:\ with the current date as a filename
            string path;
            path = "D:\\MySqlBackup" + year + "-" + month + "-" + day +"-" + hour + "-" + minute + "-" + second + "-" + millisecond + ".sql";
            StreamWriter file = new StreamWriter(path);


            ProcessStartInfo psi = new ProcessStartInfo();
            psi.FileName = "mysqldump";
            psi.RedirectStandardInput = false;
            psi.RedirectStandardOutput = true;
            psi.Arguments = string.Format(@"-u{0} -p{1} -h{2} {3}",
                "root1", "root", "localhost", "schoolmanagement");
            psi.UseShellExecute = false;

            Process process = Process.Start(psi);

            string output;
            output = process.StandardOutput.ReadToEnd();
            file.WriteLine(output);
            process.WaitForExit();
            file.Close();
            process.Close();
}



现在在这里我是
的例外



now here i got exception as

System.ComponentModel.Win32Exception: The system cannot find the file specified at this line(Process process = Process.Start(psi);)



我该如何解决我的问题,请问有人可以帮助我吗?
在此先感谢



how do i resolve my problem can any one help me please
thanks in advance

推荐答案

两个潜在的问题/原因:
1)您可能在Vista/Win7下写入磁盘根目录时遇到权限问题.最好不要依赖在那里存储信息.
2)系统找不到"mysqldump"作为可执行文件.确保已正确安装,或指定程序的完整路径
Two potential problems / causes:
1) You may have permissions problems writing to the root of a disk under Vista/Win7. it is good idea not to rely on storing info there.
2) The system cannot find "mysqldump" as an executable. Make sure it is installed correctly, or specify the full path to the program


与其尝试从输出中获取数据并写入文件,请尝试将备份直接定向到磁盘(注意4反斜杠) ):
Instead of fetching the data from output and writing to a file, try directing the backup directly to disk (note 4 backslashes):
...
path = "D:\\\\MySqlBackup" + year ...
...
psi.Arguments = string.Format(@"-u{0} -p{1} -h{2} {3} > {4}",
                "root1", "root", "localhost", "schoolmanagement", path)
...


输出可能会非常大(取决于数据库大小),因此除非您需要解释它,否则您不应在程序中路由它.

还要捕获 StandardOutput [StandardError [


The output may be extremely large (depending on the database size) so you shouldn''t route it through the program unless yo need to interpret it.

Also catch the StandardOutput[^] and StandardError[^] from the process to see if something goes wrong.


这篇关于备份mysql数据库时发生异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆