Problem with mysqldump: "--defaults-extra-file" option is not working as expected Problem with mysqldump: "--defaults-extra-file" option is not working as expected windows windows

Problem with mysqldump: "--defaults-extra-file" option is not working as expected


I found the answer: --defaults-extra-file must be the first option. This works as expected:

...\right_path\mysqldump --defaults-extra-file=d:\1.cnf                         --add-drop-database --databases my_database_name


Also meet this problem. Found there's another situation that would cause --defaults-extra-file option not recognized.

When you changed IFS in script, it's possible to hit this problem. The solution is to reset IFS before execute mysql statement.

For reference.


For future reference:

The accepted answer is correct and it is required to place --defaults-extra-file option at the first position.

To try it with containers one option is:

$ docker network create dbnet$ docker run --network dbnet -it --rm \    --name db -e MYSQL_ROOT_PASSWORD=example \    mysql echo "[client]\npassword=example\n">.mydbcreds.cnf  $ docker run --network dbnet -it --rm \    --name db-client -v "$PWD:/app/" mysql \    mysql --defaults-extra-file=/app/.mydbcreds.cnf \        --host db --user root \        -e "SHOW SCHEMAS;"

Not to forget to keep credentials safe and out of VCS:

echo ".mydbcreds.cnf">>.gitignore

The file can contain all connection parameters (host, user, etc.).

Unfortunately, this file can not contain database name, which would be awesome to have a different file per environment.Now we have all for connection in file and DB name set in the command.