MariaDB - mysqldump: Got error: 1045: "Access denied for user 'username'@'localhost' (using password: NO)" when trying to connect

Scenario:

Today when was trying to take logical backup of MariaDB database by using below 
Shell> mysqldump DatabaseName > DatabaseName.sql

got below error

Shell> mysqldump MariaDB>MariaDB1.sql
error: Found option without preceding group in config file: /etc/my.cnf.d/server.cnf at line: 6
mysqldump: Got error: 1045: "Access denied for user 'username'@'localhost' (using password: NO)" when trying to connect

Solution:

Checked the server.cnf file but could not find anything missing. Found out that if you will use root with password that will work. Used the below statement and it worked.


Shell> mysqldump -u root -p DatabaseName > BackupFileName.sql