September 20, 2014

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.

About Peter Zaitsev

Peter managed the High Performance Group within MySQL until 2006, when he founded Percona. Peter has a Master's Degree in Computer Science and is an expert in database kernels, computer hardware, and application scaling.

Comments

  1. sbester says:

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

    [mysqld]
    group=mysql

    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

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

  3. James Day says:

    We have deprecated the use of prefixes to improve the reliability of option handling starting from 5.6.13. See “Option prefixes deprecated” http://mysqlblog.fivefarmers.com/2013/08/02/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

  4. James,

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

Speak Your Mind

*