Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm writing a Windows batch file. On the ordinary command line, we'd have:

mysql -u root -p dbname
Enter password: [types password]
show tables;

Is there a way I can supply the password, and 'show tables' in the batch file so the user doesn't have to type it in - they can just run the batch file?

share|improve this question

Password:

mysql -u root --password=p4ssw3rd dbname

Commands:

mysql ... -e "show tables;"
echo show tables; | mysql ...
(
    echo foo;
    echo bar;
) | mysql ...
mysql ... < commands.txt
share|improve this answer
    
very good! i normally use "<" – kokbira Jun 26 '11 at 4:00

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.