Improve compatibility with different MySQL versions

This fixes an issue spotted by Nikerabbit in https://bugzilla.wikimedia.org/show_bug.cgi?id=58502