As @maxschlepzig said in a comment,
Note that there is the MYSQL_PWD environment variable which is read by mysql if you don't specify -p.
So in bash:
read -s -p "Enter the mysql password for $DBUSER @ $DBNAME: " DBPASS
export MYSQL_PWD="$DBPASS"
mysqldump -u $DBUSER $DBNAME > dump.sql
# once you are done
export MYSQL_PWD=""