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 > bak_%DATE%.sql 2> sql_error.log

Contents of config.cnf:

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'@'' (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:

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

According to the Location in Windows section in the MariaDB knowledge base it looks for the my.cnf file in various places. In Windows, I found the default my.cnf under C:\my.cnf. I edited this file and added the password under the [client] group.

The following command works without specifying a password with -p or using --defaults-extra-file, as it uses the configuration file located at C:\my.cnf:

@echo off
C:\MySQL\bin\mysqldump.exe -u root --all-databases > bak_%DATE%.sql 2> sql_error.log

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.