Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

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


mysql -u root --password=p4ssw3rd dbname


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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .