Can't read password from config using --defaults-extra-file in MySQL I am trying to backup all databases automatically using a batch script. The password is read from a config file called config.cnf. Below is the batch script:

@echo off
C:\MySQL\bin\mysqldump.exe --defaults-extra-file=config.cnf -u root --all-databases &gt; bak_%DATE%.sql 2&gt; sql_error.log


Contents of config.cnf:

[mysqldump]
password = mypassword


When running the batch the following error messages are returned:

Could not open required defaults file: config.cnf
Fatal error in defaults handling. Program aborted
mysqldump: Got error: 1045: "Access denied for user 'root'@'127.0.0.1' (using password NO)" when trying to connect


For some reason, the config.cnf is not being read and the execution of the script fails. I am not sure why this is happening.

Edit: Version of the database is MySQL version 14.16 Distrib 5.2.4 MariaDB.
Running the batch script as Administrator still results in same error message, as does also modifying the config file, as well as modifying the group to [client]. Found an alternative solution, which is answered below.
It looks like the access issue due to permissions level.
Try running the batch file as administrator by right clicking on it and then selecting Run as administrator ,Try wrapping your password with in '' if it contains special characters,Try removing any extra space that might be getting added,also please find few more solutions to similar problem here :

As per examples from http://dev.mysql.com/doc/refman/5.7/en/option-files.html
The password should look like:

[client]
# The following password will be sent to all standard MySQL clients
password="my password"