Showing posts with label MySQL. Show all posts
Showing posts with label MySQL. Show all posts

Thursday, August 22, 2013

Export or Backup MySQL Database in separate file using Shell Script


Live projects database are always critical for Clients and Companies and if the development phase is still in progress than you need to take backup of database on daily basis for safety concerns. i came across with the same situation and for that i've created a simple script which will take backup of your database.

it will export table wise separate sql file rather than one big SQL file. you can also make zip file for all the tables with gzipped option (dbname.gz).

This script is created for MySQL database only and it;s been tested on Mac OS X and Ubuntu OS.
You need to set path for MySQLDump and MySQL in script file.

Share:

Friday, August 2, 2013

Import MySQL .sql script from Java

Sometimes it is nice to programmatically run .sql scripts on a MySQL database using Java. This is easily achieved by using a simple ScriptRunner Class from the iBatis apache project. iBatis project is having it's own dependencies and if you want to check that class you need to add all the dependency. To overcome this issue i came across with a Slightly modified version of the com.ibatis.common.jdbc.ScriptRunner class from the iBATIS Apache project. it only removed dependency on Resource class and a constructor.

I made a simple java project which will execute the .sql script in local MySQL database.

Below are the steps to create new project and execute the .sql script in Java project.

Share: