Share via


How to take mysql backup and restore using windows C#

Question

Monday, March 19, 2012 11:36 AM

Hi 

   How to take mysql backup and restore using windows C#?

   

All replies (5)

Monday, March 19, 2012 2:52 PM ✅Answered

Take a look at this site. Here you will find the following code:
http://realm3.com/articles/how_to_schedule_regular_mysql_backups_in_windows

c:\path-to-mysql>\bin\mysqldump -u[user] -p[password] --result-file="c:\path>\backup.%DATE:~0,3%.sql" [database]

 


Wednesday, March 21, 2012 2:42 AM ✅Answered

Use Command to backup/resotre your mysql is a suggested way.

Please see it in its offical website:

For backup:

http://dev.mysql.com/doc/mysql-enterprise-backup/3.6/en/ihb-meb-compatibility.html 

For restore:

http://docs.oracle.com/cd/E17952_01/refman-5.1-en/mysql-cluster-programs-ndb-restore.html 

Best Regards

Neddy Ren[MSFT]
MSDN Community Support | Feedback to us


Wednesday, March 21, 2012 2:46 AM ✅Answered

Hi Ajith,

The command to backup database is :
-u USER -pPASS --databases DATABASE -r > path/to/file.sql

And C# code for this is:

Process.Start(@"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysqldump.exe", ("-u user -p***** --databases DB -r \" + path + "\";

Regards, http://shwetamannjain.blogspot.com


Wednesday, March 21, 2012 2:48 AM ✅Answered

H iAjith,

The command to restore database is :
-u USER -pPASS DATABASE < path/to/file.sql

So, C# code will be:

Process.Start(@"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe", ("-u user -p**** < \" + path + "\"));

Process myProcess = new Process();
            myProcess.StartInfo.FileName = @"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe";
            myProcess.StartInfo.UseShellExecute = false;
            myProcess.StartInfo.WorkingDirectory = @"C:\Program Files\MySQL\MySQL Server 5.5\bin\;
            myProcess.StartInfo.Arguments = "-u user -p**** PIEx < + "\" + path + "\";
            myProcess.StartInfo.RedirectStandardInput = false; myProcess.StartInfo.RedirectStandardOutput = false;
            myProcess.Start();
 
            myProcess.WaitForExit();
            myProcess.Close();

Regards, http://shwetamannjain.blogspot.com


Sunday, June 24, 2012 8:27 AM

There is an alternative way to do this.

read here:

http://www.codeproject.com/Articles/256466/Making-Your-Own-MySQL-Backup-and-Restore-Tools-in