16

My main MySQL user's /home//my.cnf file looks like this (Linux system):

[client]
host=localhost
user=<user>
password=********
database=h2o_amr

I want to point mysqldump to this config file, which is in the directory where the mysqldump file will be written:

[client]
host=localhost
user=<user>
password=********

How do I point mysqldump to this config file? I have searched for an answer to this in the man pages and the Internet before posting this question.

0

2 Answers 2

37

There are three options to change the default behavior:

  • --no-defaults: Don't read default options from any option file.
  • --defaults-file=#: Only read default options from the given file #.
  • --defaults-extra-file=#: Read this file after the global files are read.

This information was copied from the integrated manual, i.e.
mysqldump --help | grep -A7 'Default options'.

Note: The parameter needs to be in first position if you add others parameters, if not it will not be recognized.

2

According to the documentation, there is a --defaults-file=PATH option that does exactly what you need. I tried it myself with mysqldump and it appears to have worked.

There are also other ways to have MySQL read option files without using that argument: using the default paths MySQL clients search through to compile the list of options (1st and 2nd table).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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