Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shell script to import mysql dump file

I'm new to mysql. My requirement is to create a shell script to import a sql dump file into mysql in linux and this script should be called by java program for the restoration to take on a button click.

Please advice me on this.

Regards,

Chandu.

like image 616
Chandu Avatar asked Apr 14 '10 09:04

Chandu


1 Answers

It can be done by using mysql

mysql --user=USERNAME --password=PASSWORD DATABASE < DATABASE.sql

EDIT:

To place this in a script:

file loaddb.sh:

mysql --user=USERNAME --password=PASSWORD DATABASE < $1.sql

add execute-permission by

chmod +x loaddb.sh

you would call it:

loaddb.sh YOURDBNAME

like image 73
stacker Avatar answered Sep 19 '22 14:09

stacker