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:
[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.