0

hi i am using a code to add a sql file to my database in a batch file . it works .

my code

C:
cd\xampp\mysql\bin
mysql -u root -e "source C:\xampp\htdocs\internet_wk_1.7\db\master_db.sql" kani

the case is i want to get user input values to user name , password and database name , instead of hard code those values .

currently my username hard coded as root

i want to do like this

user should get a message

please enter your user name :

when i did it

 please enter your password :

after that

 please enter your database name :

then the script shout proceed . how to do this , please help . thanks in advance

1 Answer 1

1

Use set with the /P option:

@echo off
set /p username=please enter your user name:
set /P pwd=please enter your password:
set /p dbname=please enter your database name:

cd /d c:\xampp\mysql\bin
mysql -u%username% -p%pwd% -e "source C:\xampp\htdocs\internet_wk_1.7\db\master_db.sql" %dbname%

You get more details if you enter help set in a commandline window.

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

5 Comments

perfect it works , but only one problem , if i dont have a password, afer please enter your database name: , enter your password: again asking . why is that and how to solve it
@KanishkaPanamaldeniya: I don't understand your question. If you just hit enter at the prompt the variable will be empty.
@ a_horse_with_no_name , yes but if i enter with out a value ,it again asks for the password after database name
@KanishkaPanamaldeniya: not on my computer with Windows XP. I have no idea why it does that on your computer.
hmm , i am working on windows 7 . but it is ok , the code is working , thank you very much

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.