MySQL and predictive option handling – beware

MySQL and predictive option handling – beware


MySQL command line utilities have an interesting property – if you only use the prefix of the option or command it will go over the list of available command and if there is only one command with matching prefix it will execute it with no warnings or any kind, otherwise it will report the error. For example mysqladmin e works as there is only one command “extended-status” which starts with “e” mysqladmin f however does not work because there are multiple commands which start with “f”.

This behavior can cause all kings of issues especially if you make a typo. I made one today (thankfully on the test box). MySQL init Scripts use “stop” and “start” commands to start and stop the server while mysqladmin uses “shutdown”. I mixed this while trying to stop Percona Server:

It would be quite confusing if mysqladmin would have “stop” command which does not do the same thing as “shutdown” . And it does not. The commands it has are
“start-slave” and “stop-slave” though as these are the only commands with such prefixes they are matched to “start” and “stop” appropriately.

I think such automated option prediction is very dangerous and it gets more dangerous the more options are added for the tools as it is more likely your mistake can be actually matching something… I think much better solution would be to have explicitly created synonyms and shortcuts if they are needed. For example “extended-status” is rather option and we can allow “extended” shortcut for it or might be even “ext” but allowing “e” is an overkill.


Share this post

Comments (4)

  • sbester Reply

    same thing with my.cnf options. I’ve seen things like this quite often go unnoticed:


    Of course, that means set group-concat-max-len to a value of “mysql”.
    Since “mysql” is an invalid number, it’s converted to 0.
    And minimum value for the variable is 4 we end up with this:

    option ‘group_concat_max_len’: unsigned value 0 adjusted to 4

    October 30, 2012 at 7:49 am
  • Peter Zaitsev Reply

    Indeed. Interesting catch, Shane… you might assume t here is a group option as there is a “user” option

    October 30, 2012 at 1:55 pm
  • James Day Reply

    We have deprecated the use of prefixes to improve the reliability of option handling starting from 5.6.13. See “Option prefixes deprecated” . It isn’t just options and tools but server plugins can also add options and suddenly break previously working settings.

    Views are my own. For an official Oracle view, consult a PR person.

    James day, MySQL Senior Principal Support Engineer, Oracle

    August 7, 2013 at 5:11 pm
  • Peter Zaitsev Reply


    Thank you for taking a time to leave a comment. Great information!

    August 7, 2013 at 7:32 pm

Leave a Reply