Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to take MySql DB backup from java

 
Sumeet Chakraborty
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 182
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
Chrome Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Backup:
/******************************************************/
//Database Properties
/******************************************************/

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

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

/***********************************************************/
// Execute Shell Command
/***********************************************************/
 
Wendy Gibbons
Bartender
Posts: 1110
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 5
Java MySQL Database Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you sarath j nair for your sample, you make my day bright again...
 
sarath j nair
Greenhorn
Posts: 11
Chrome Eclipse IDE Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are always welcome Arief Ginanjar .....
 
Isuru Ranawaka
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 76
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic