6

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.

2 Answers 2

6

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

Sign up to request clarification or add additional context in comments.

6 Comments

Hi stacker, Thanks for ur reply. But my requirement is to create a shell script that do this job as specified in the description. Please advice me
Chandu, add #!/bin/bash as the first script line, replace DATABASE.sql with $1 and you're all set.
Hi Tomislav, Thank for your reply. I'm not clear about $1 can you explain me on this? If I specified $1 then where I have to keep dump file path for restoring.
$1 is a placeholder for a parameter passed to you script
Thanks Stacker, so where should I place the execute permission "chmod +x loaddb.sh" because I want to run this script from a java program & explain me the way about how to call this script from java.
|
1

See this; it might be beneficial:

#!/bin/sh
echo "ENTER DATA BASE NAME:"
read dbname
echo "ENTER DATABASE USER NAME:"
read dbuser
echo "ENTER DATASE PASSWORD:"
read dbpassword
mysqldump -u $dbuser -p$dbpassword $dbname>$dbname".sql"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.