Click here to Skip to main content
12,248,339 members (41,351 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: .NET3.5 C# .NET
i want to take backup of the MYSQL database i have try the following code it;s not working properly
DateTime backupTime = DateTime.Now;
                   int year = backupTime.Year;
                   int month = backupTime.Month;
                   int day = backupTime.Day;
                   int hour = backupTime.Hour;
                   int minute = backupTime.Minute;
                   int second = backupTime.Second;
                   int ms = backupTime.Millisecond;
 
                   String tmestr = backupTime.ToString();
                   tmestr = "C:\\" + year + "-" + month + "-" + day + "-" + hour + "-" + minute + ".sql";
                   StreamWriter file = new StreamWriter(tmestr);
                   ProcessStartInfo proc = new ProcessStartInfo();
                   string cmd = string.Format(@"-u {0} -p {1} -h {2}  {3} >  {4};", "root", "", "localhost", "globasys", "backup.sql");
                   proc.FileName = @"C:\Program Files\MySQL\MySQL Server 6.0\bin\mysqldump";
                   proc.RedirectStandardInput = false;
                   proc.RedirectStandardOutput = true;
                   proc.Arguments = cmd;//"-u root -p smartdb > testdb.sql";
                   proc.UseShellExecute = false;
                   Process p = Process.Start(proc);
                   string res;
                   res = p.StandardOutput.ReadToEnd();
                   file.WriteLine(res);
                   p.WaitForExit();
                   file.Close();
this code create the . SQL file but when restore this file in to data it display the error message SQL dump error following txt file display the error message
Query:
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT *//*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */
 
Error occured at:2011-10-17 15:23:28
Line no.:8
Error Code: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */' at line 1
 
Query:
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT *//*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */
 
Error occured at:2011-10-18 15:33:23
Line no.:8
Error Code: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */' at line 1
 
Query:
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT *//*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */
 
Error occured at:2011-10-18 15:34:56
Line no.:8
Error Code: 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */' at line 1
how to take backup of the MYSQL database in C#.NET
Posted 18-Oct-11 1:08am
Edited 18-Oct-11 1:17am
v3
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Using MySqlDump is a real mission to get right. Take a look at my article on MySql BackUp Utility[^]. The article is in VB.Net but it is a separate class and can be used in C# apps.

Hope this helps
  Permalink  
Comments
sangita navale 20-Oct-11 7:46am
   
in your article code MYSQL.data.dll file can not found & when add this file to your code it will not get the reference of this file .can you please tell me the version of the MYSQL dll file because i have 5.0.9 version
Wayne Gaylard 20-Oct-11 8:31am
   
Have you installed the MySql Connector for .Net ? If you have, then you just have to remove the reference to MySql.Data in my project and then add a reference to your installed version. Then you will have to compile the project again, and it should all work. Sorry that I cannot remember the version I used for that project, and it is not on the machine I am using at the moment.
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

This solution works for small size db. when it runs for taking db of big size ( arnd Gb) it fails..
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160426.1 | Last Updated 25 Jun 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100