Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I run the following command from the Windows command line to backup my database:

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

where d:\1.cnf contains the following:

[client] user="my_user" password="my_password" 

Unfortunately, I got the following error message:

mysqldump: unknown variable 'defaults-extra-file=d:\1.cnf' 

If I do:

...\right_path\mysqldump --add-drop-database --databases my_database_name                          --user="my_user" --password="my_password" 

it works as expected.

What am I doing wrong ?

like image 937
Misha Moroshko Avatar asked Oct 01 '10 02:10

Misha Moroshko


People also ask

What privileges are needed for mysqldump?

mysqldump requires at least the SELECT privilege for dumped tables, SHOW VIEW for dumped views, TRIGGER for dumped triggers, LOCK TABLES if the --single-transaction option is not used, and (as of MySQL 8.0.21) PROCESS if the --no-tablespaces option is not used.

Which of the following parameters belong to the Mysqldump utility for backup?

The parameters are as following: -u [user_name]: It is a username to connect to the MySQL server. To generate the backup using mysqldump, 'Select' to dump the tables, 'Show View' for views, 'Trigger' for the triggers.

What is single transaction in Mysqldump?

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.


2 Answers

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 
like image 112
Misha Moroshko Avatar answered Sep 21 '22 21:09

Misha Moroshko


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.

like image 29
cynkiller Avatar answered Sep 22 '22 21:09

cynkiller