How do I connect to a database with a blank password using a shell script? ## connect to mysql and source backup file ##
USER="root"
PASS=""

mysql -u$USER -p$PASS database_name &lt; 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.
If root has no password you could just do this:
mysql -u$USER database_name &lt; backup.sql

If you want to code so that root can be given a password later, do this in the script
USER=&quot;root&quot;
PASS=&quot;&quot;
if [ &quot;${PASS}&quot; == &quot;&quot; ]
then
    PASSWORD=&quot;&quot;
else
    PASSWORD=&quot;-p${PASS}&quot;
fi
mysql -u${USER} ${PASSWORD} database_name &lt; backup.sql

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