snippetsqlMinor
How do I connect to a database with a blank password using a shell script?
Viewed 0 times
scriptconnectwithblankpassworddatabaseshellusinghow
Problem
## connect to mysql and source backup file ##
USER="root"
PASS=""
mysql -u$USER -p$PASS database_name < backup.sqlAbove 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.
Solution
If root has no password you could just do this:
If you want to code so that root can be given a password later, do this in the script
Give it a Try !!!
CAVEAT
If is usually not a good idea to have root without a password. Please give it one.
mysql -u$USER database_name < backup.sqlIf you want to code so that root can be given a password later, do this in the script
USER="root"
PASS=""
if [ "${PASS}" == "" ]
then
PASSWORD=""
else
PASSWORD="-p${PASS}"
fi
mysql -u${USER} ${PASSWORD} database_name < backup.sqlGive it a Try !!!
CAVEAT
If is usually not a good idea to have root without a password. Please give it one.
Code Snippets
mysql -u$USER database_name < backup.sqlUSER="root"
PASS=""
if [ "${PASS}" == "" ]
then
PASSWORD=""
else
PASSWORD="-p${PASS}"
fi
mysql -u${USER} ${PASSWORD} database_name < backup.sqlContext
StackExchange Database Administrators Q#41070, answer score: 6
Revisions (0)
No revisions yet.