Click here to Skip to main content
15,892,674 members

how to take backup of the MYSQL database in C#.NET

vrushali katkade asked:

Open original thread
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
Tags: C#, .NET (.NET 3.5)

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900