Best practice states that the /home/user/.my.cnf or /root/.my.cnf file should be created (depending on what user you are taking the dump with) with the appropriate credentials before taking a mysql dump. This is not mandatory but certainly makes life easier when working with mysql
Creating the file is as easy as:
vim /root/.my.cnf
[client] user: root password: mypassword
You can view your mysql databases without logging into mysql with the following command:
mysql -e "show databases"or
mysqlshow