File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes How to take MySql DB backup from java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "How to take MySql DB backup from java" Watch "How to take MySql DB backup from java" New topic
Author

How to take MySql DB backup from java

Sumeet Chakraborty
Ranch Hand

Joined: Feb 05, 2009
Posts: 45
Hi all

I am trying to build a java utility which will enable me to take the backup of my MySql Database. I want the backup to be taken and dumped in a sql file in some location of my file system. Is there any way I could do it using Java code ? I searched a lot but didn't get any satisfying solution

Please help.

Thanks and Regards
Sumeet
Fatih Keles
Ranch Hand

Joined: Sep 01, 2005
Posts: 182
Hi Sumeet,

Why do you need that? There is a command line utility called mysqldump for this purpose. Also you can find the following links useful from mysql manual.

http://dev.mysql.com/doc/refman/5.1/en/backup-methods.html
http://dev.mysql.com/doc/refman/5.0/en/copying-databases.html

Regards,

Fatih.
Sumeet Chakraborty
Ranch Hand

Joined: Feb 05, 2009
Posts: 45
Thanks Fatih

But thats what my boss has asked me to do and thats what the requirement is ..so cant help

Please help
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38075
    
  22
You will probably have to call it from Runtine.exec, and that is Java ( ), but make sure to read when runtime.exec() won't by Michael Daconta first.
sarath j nair
Greenhorn

Joined: Nov 10, 2011
Posts: 11

Backup:
/******************************************************/
//Database Properties
/******************************************************/

/***********************************************************/
// Execute Shell Command
/***********************************************************/

Restore:
/******************************************************/
//Database Properties
/******************************************************/

/***********************************************************/
// Execute Shell Command
/***********************************************************/
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 1107

Sumeet Chakraborty wrote:Thanks Fatih

But thats what my boss has asked me to do and thats what the requirement is ..so cant help

Please help


Have you mentioned the command line utility to your boss? don't just presume they know everything and are being akward on purpose.
arief ginanjar
Greenhorn

Joined: Jan 09, 2011
Posts: 5

Thank you sarath j nair for your sample, you make my day bright again...
sarath j nair
Greenhorn

Joined: Nov 10, 2011
Posts: 11

You are always welcome Arief Ginanjar .....
Isuru Ranawaka
Greenhorn

Joined: Jan 13, 2013
Posts: 2
Sumeet Chakraborty wrote:Hi all

I am trying to build a java utility which will enable me to take the backup of my MySql Database. I want the backup to be taken and dumped in a sql file in some location of my file system. Is there any way I could do it using Java code ? I searched a lot but didn't get any satisfying solution

Please help.

Thanks and Regards
Sumeet


Hi Sumeet, I created a solution myself. Please take a look and get if you think it will be useful.

It is not a complex solution, I used some SHOW CREATE and SELECT commands and parsed the strings.
I Tried to make it look alike to a backup you take from Navicat software.
Here is the code.

Anindya Roy
Ranch Hand

Joined: May 11, 2014
Posts: 70
Example http://www.webtuts.in/java-application-and-database-backup/


http://www.webtuts.in
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to take MySql DB backup from java
 
Similar Threads
move tables from one computer to another?
How to take automatic backup?
Embedding MySQL Database in Java Application
Backing up database through java
Need External Back Up in Java Web Application