首页 新闻 会员 周边 捐助

为什么C#用mysqldump.exe备份mysql数据库函数没备份下来

0
悬赏园豆:10 [已关闭问题] 关闭于 2011-07-07 10:49

/// <summary>
        /// 备份数据库
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void t_tsmi_BackupDatabase_Click(object sender, EventArgs e)
        {
            try
            {
                SaveFileDialog saveFileDialog = new SaveFileDialog();
                saveFileDialog.Filter = "数据备份脚本.sql|(*.sql)";
                saveFileDialog.FileName = (DateTime.Now.ToString("yyyyMMddhhmmss") + ".sql");
                if (saveFileDialog.ShowDialog() == DialogResult.OK)
                {
                    if (saveFileDialog.FileName != null)
                    {
                        string location = Application.StartupPath.ToString();                      
                        ProcessStartInfo psi = new ProcessStartInfo(location + @"\mysqldump.exe");
                        psi.Arguments = @"--default-character-set utf8 -u root --password=sa --database logclient31 > backup.sql";
                        psi.UseShellExecute = false;
                        psi.RedirectStandardOutput = true;
                        psi.RedirectStandardInput = true;
                        psi.RedirectStandardError = true;
                        psi.CreateNoWindow = true;
                        Process pro = Process.Start(psi);
                        Stream baseStream = pro.StandardOutput.BaseStream;
                        StreamReader sr = new StreamReader(baseStream, System.Text.Encoding.UTF8);
                        string strSqldump = sr.ReadToEnd();
                        FileStream fs = File.Create(saveFileDialog.FileName);
                        byte[] arr = UnicodeEncoding.UTF8.GetBytes(strSqldump);
                        fs.Write(arr, 0, arr.Length);
                        fs.Flush();
                        fs.Close();
                        pro.Close();
                        //数据库已成功备份
                    }
                }
            }
            catch (Exception ex)
            {
                //数据库备份失败            }
        }

其中备份出来的脚本文件中没有 create function 语句。
囧嗿″翫▓的主页 囧嗿″翫▓ | 初学一级 | 园豆:118
提问于:2011-07-06 14:35
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册