开发者

Shell script to import mysql dump file

开发者 https://www.devze.com 2022-12-27 08:18 出处:网络
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 cli

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.


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


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"
0

精彩评论

暂无评论...
验证码 换一张
取 消