• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • Carey Brown
  • Stephan van Hulst
Bartenders:
  • Frits Walraven
  • fred rosenberger
  • salvin francis

How to take MySql DB backup from java

 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 182
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Marshal
Posts: 73243
332
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 11
Eclipse IDE Tomcat Server Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Backup:
/******************************************************/
//Database Properties
/******************************************************/

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

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

/***********************************************************/
// Execute Shell Command
/***********************************************************/
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 5
MySQL Database Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Tomcat Server Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are always welcome Arief Ginanjar .....
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Example http://www.webtuts.in/java-application-and-database-backup/
 
reply
    Bookmark Topic Watch Topic
  • New Topic