[MDEV-7208] mysqldump incorrectly reads the variable "database" as "databases" Created: 2014-11-26  Updated: 2015-08-17  Resolved: 2015-08-17

Status: Closed
Project: MariaDB Server
Component/s: Scripts & Clients
Affects Version/s: 5.5.40, 10.0.15
Fix Version/s: N/A

Type: Bug Priority: Trivial
Reporter: Jean Weisbuch Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: mysqldump, upstream
Environment:

Linux



 Description   

Putting a "database=some_db" (where some_db is a valid database) under the [client] section of ~/.my.cnf (or any other config files parsed by mysqldump) will result on this warning on the execution of mysqldump, even if a database (or several) are specified for the dump :

$ mysqldump --help                                                                                                   
Warning: mysqldump: ignoring option '--databases' due to invalid value 'valid_db'
mysqldump  Ver 10.14 Distrib 5.5.40-MariaDB, for debian-linux-gnu (i686)
Copyright (c) 2000, 2014, Oracle, Monty Program Ab and others.
[...]

$ mysqldump valid_db                                                                                                
Warning: mysqldump: ignoring option '--databases' due to invalid value 'valid_db'
-- MySQL dump 10.14  Distrib 5.5.40-MariaDB, for debian-linux-gnu (i686)
--
-- Host: localhost    Database: valid_db
[...]

The same happens when running "mysqldump --databases some_db"

The error message is confusing as the specified database name is valid.

The upstream bug (http://bugs.mysql.com/bug.php?id=18209) has been reported almost a decade ago and a patch that added the specific option "database" to mysqldump has been provided on the bug report but never made it to the main tree : http://lists.mysql.com/commits/6311

Another solution would be to make simply that mysqldump doesnt read the database parameter from the config file which would be safe as it should have never worked before.



 Comments   
Comment by Jean Weisbuch [ 2014-12-05 ]

As a side note, mysqladmin also doesnt like the database variable on the [client] section :

# mysqladmin
mysqladmin: unknown variable 'database=test'

Comment by Michael Widenius [ 2015-06-26 ]

This is not a bug, but wrong usage of the --database[s] option.

--databases means that all arguments, that are not options, should be treated as databases instead of tables.

Having databases=1 in an option file makes perfect sense as it changes how mysqldump works by default (working on databases instead of tables).

Adding a --database=name option would not be a good idea as database is a prefix of databases and could cause errors for anyone using 'database' in the config files.

One can only have options that is valid for all clients in the [client] section.
This is an option that is unique for mysqldump and can only be used in the [mysqldump] section.

That said, it would be nice to have a way to add in the configuration file an option to only dump one database (by default)

Comment by Sergei Golubchik [ 2015-06-26 ]

jb-boin, what is the complain here? A spurious warning? Or inability to specify a database in the config file?

Comment by Jean Weisbuch [ 2015-06-27 ]

On the other way around, if the "database=" value is set to a boolean on the [client] section, "mysqldump" will work just fine but the CLI and "mysqladmin" wont work anymore :

$ mysql
ERROR 1049 (42000): Unknown database '1'

The "database=" option could be mistakebly put on the [client] section instead of the [mysql] one by a user wanting to set the default database to connect to.
The user wouldnt notice directly that he hasnt put it on the right section as the CLI would be working "as expected" by connecting by default on the specified database, it could break backups and other scripts relying on "mysqldump" and "mysqladmin" for example.

As a possible solution, it would be better to throw a warning telling that the option might have been put on the wrong section or that abbreviation should be avoided if :

  • database is set on the [mysqldump] section to a boolean reserved word (such as 0, 1, ON, OFF) which would mean that the user used it as the databases option abbreviation and it would be better to use its complete naming to avoid confusion as both exists on different tools.
  • database or databases is set on the [client] section which shouldnt happen as it will most probably lead to a variable behavior depending on the client reading it.

The fact that the warning has expanded the option to a different one (setting "database" but ending up on an error on the "databases" invalue value is a bit confusing if you dont know there is an auto completion of abbreviations).

Comment by Sergei Golubchik [ 2015-06-27 ]

The server in 10.1 supports the option --disable-getopt-prefix-matching. It would be a bit difficult to add that to clients too, but possible. Then one could put it in [client] or even [client-server] section and and database will never mean databases anymore.

Would that be a solution?

Comment by Sergei Golubchik [ 2015-08-17 ]

This is not a bug, but a consequences of the intentional and documented behavior.

While I agree that this behavior of confusing, I'm not sure what exactly the best fix could be.
And in the absence of feedback I'd rather close this issue.

Please, feel free to reopen it or add a comment if you still want us to fix it.

Generated at Thu Feb 08 07:17:50 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.