Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-7208

mysqldump incorrectly reads the variable "database" as "databases"

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Trivial
    • Resolution: Won't Fix
    • Affects Version/s: 5.5.40, 10.0.15
    • Fix Version/s: N/A
    • Component/s: Scripts & Clients
    • 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.

        Gliffy Diagrams

          Attachments

            Activity

            Hide
            jb-boin Jean Weisbuch added a comment -

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

            # mysqladmin
            mysqladmin: unknown variable 'database=test'
            Show
            jb-boin Jean Weisbuch added a comment - As a side note, mysqladmin also doesnt like the database variable on the [client] section : # mysqladmin mysqladmin: unknown variable 'database=test'
            Hide
            monty Michael Widenius added a comment - - edited

            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)

            Show
            monty Michael Widenius added a comment - - edited 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)
            Hide
            serg Sergei Golubchik added a comment -

            Jean Weisbuch, what is the complain here? A spurious warning? Or inability to specify a database in the config file?

            Show
            serg Sergei Golubchik added a comment - Jean Weisbuch , what is the complain here? A spurious warning? Or inability to specify a database in the config file?
            Hide
            jb-boin Jean Weisbuch added a comment -

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

            Show
            jb-boin Jean Weisbuch added a comment - 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).
            Hide
            serg Sergei Golubchik added a comment -

            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?

            Show
            serg Sergei Golubchik added a comment - 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?
            Hide
            serg Sergei Golubchik added a comment -

            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.

            Show
            serg Sergei Golubchik added a comment - 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.

              People

              • Assignee:
                Unassigned
                Reporter:
                jb-boin Jean Weisbuch
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: