Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specifying separate config file on mysqldump command line

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.

like image 750
octopusgrabbus Avatar asked May 23 '12 17:05

octopusgrabbus


People also ask

How use Mysqldump command line?

To dump/export a MySQL database, execute the following command in the Windows command prompt: mysqldump -u username -p dbname > filename. sql . After entering that command you will be prompted for your password.

What is single transaction in Mysqldump?

Mysqldump with Transactions The --single-transaction flag will start a transaction before running. Rather than lock the entire database, this will let mysqldump read the database in the current state at the time of the transaction, making for a consistent data dump.

How do I find Mysqldump path?

On Windows, add the path to mysqldump to the executable to your PATH environment variable. You can then run mysqldump from any folder. Typically common tools are added the PATH variable by installers, but sometimes if you are installing a tool manually you need to add it yourself.

What is path to Mysqldump?

The mysqldump tool is located in the root/bin directory of the MySQL installation directory.


2 Answers

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.

like image 103
nosid Avatar answered Sep 18 '22 09:09

nosid


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).

like image 38
Toote Avatar answered Sep 20 '22 09:09

Toote