Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. 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
## connect to mysql and source backup file ##

mysql -u$USER -p$PASS database_name < backup.sql

Above is my shell script which I used to source database but still its asking for password. I just want to know how can I source database in case of blank password. If root password is not blank than it works fine.

share|improve this question
An empty database password is not acceptable, ever, and and empty root password is completely unthinkable. – Michael - sqlbot Apr 28 '13 at 14:02
It is also not a good idea (especially on a shared system) to have the user+password on the command line: anyone logged into the machine can potentially read them from the task list. See and for the preferred alternative. – David Spillett Oct 21 '13 at 14:40

If root has no password you could just do this:

mysql -u$USER database_name < backup.sql

If you want to code so that root can be given a password later, do this in the script

if [ "${PASS}" == "" ]
mysql -u${USER} ${PASSWORD} database_name < backup.sql

Give it a Try !!!


If is usually not a good idea to have root without a password. Please give it one.

share|improve this answer

Use --password instead of -p:

mysql "--username=$USER" "--password=$PASS" < backup.sql
share|improve this answer

Your Answer


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.