MySQL and predictive option handling – beware

October 29, 2012
Author
Peter Zaitsev
Share this Post:

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.

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments

Far
Enough.

Said no pioneer ever.
MySQL, PostgreSQL, InnoDB, MariaDB, MongoDB and Kubernetes are trademarks for their respective owners.
© 2026 Percona All Rights Reserved