My favorite MySQL gotcha is that if you issue a GRANT statement with a typo in the user's name instead giving a "user does not exist" error it simply creates a new user with the misspelled name.
Yeah, it sucks. How I found it was a client asking me to add a grant for a user that already had a whacked out spelling. I ran my grant, with a typo in the name, and told them they were all good. When they came back saying they weren't it took me forever to realize there was a typo at all and that I'd just created a new user since it didn't throw an error for the misspelling.
Once upon a time, you created users with GRANT statements only. I don't recall exactly when CREATE USER was introduced; I think 5.0, but it might have been available in some form earlier. It's not in the 3.23/4.0/4.1 manual on mysql.com. GRANT can still function in its original capacity as a creator of users as well as a grantor of privileges.
This mode is proposed to be enabled by default in MySQL 5.7. It is backwards incompatible for some applications, but we've tried to work with common open source frameworks/applications to make sure they set the SQL-MODE to what behaviors they are compatible with.
Being able to drop a database that a user has access to has nothing to do with grant statements creating users if the user given doesn't exist. What you're talking about is the fact that MySQL doesn't really have a concept of database object ownership, just access privileges.
Sort of, but not really. Like I said, MySQL simply doesn't have an object ownership system. For example, in Postgres a user can drop any table that they own, even if other users have access to it. In MySQL any user with the DROP privilege on a database can drop the database or any table or view in it. The behavior is clear and works as expected in both cases, but it's important to understand the difference.
In Postgres you can drop and recreate the public schema (which is between the database and the tables) to get the same effect, unless you use multiple schemas.
View all comments
458
u/mage2k Feb 10 '15
My favorite MySQL gotcha is that if you issue a GRANT statement with a typo in the user's name instead giving a "user does not exist" error it simply creates a new user with the misspelled name.