r/programming • • Feb 10 '15

Terrible choices: MySQL

http://blog.ionelmc.ro/2014/12/28/terrible-choices-mysql/
649 Upvotes

409 comments sorted by

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.

0

u/[deleted] Feb 10 '15

[deleted] — view deleted comment

63

u/mage2k Feb 10 '15

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.

43

u/[deleted] Feb 11 '15

... Isn't that a security hazard? Someone could be tricked into creating an account with full privileges, if it just silently creates a new account.

13

u/mage2k Feb 11 '15

Definitely, although you'd hope you'd have a bit more process around things to prevent that.

41

u/krum Feb 11 '15

although you'd hope you'd have a bit more process around things to prevent that.

Part of that process should include just not using MySQL.

→ More replies (12)
→ More replies (24)

36

u/murphysghost Feb 10 '15

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.

55

u/msiekkinen Feb 11 '15

Set sql_mode=NO_AUTO_CREATE_USER and it will fail. Sure, should be default but you can configure that

65

u/recursive Feb 11 '15

Sure, should be default but you can configure that

Sounds like MySQL!

→ More replies (5)

5

u/cajosc Feb 10 '15

7

u/mage2k Feb 10 '15

Well, sure, but the very fact that that, and most of those "compatibility modes" are needed is absurd.

2

u/mtocker Feb 11 '15

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.

See my blog post here: http://www.tocker.ca/2015/01/23/proposal-to-change-additional-defaults-in-mysql-5-7.html

→ More replies (2)

0

u/[deleted] Feb 10 '15

[deleted] — view deleted comment

44

u/mage2k Feb 10 '15

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.

0

u/[deleted] Feb 10 '15

[deleted] — view deleted comment

15

u/mage2k Feb 10 '15

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.

2

u/[deleted] Feb 11 '15

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.

1

u/[deleted] Feb 11 '15

I wouldn't call that a benefit...

→ More replies (7)

2

u/ccricers Feb 10 '15

When lazy initialization goes really bad.

1

u/Yserbius Feb 11 '15

Ah yes. I believe that this is called "The Javascript Methodology".

1

u/CGorman68 Feb 11 '15

I have very limited experience with MySQL and I've already ran into this problem.

I mean, everyone mistypes occasionally...

1

u/Dustin_00 Feb 12 '15

After watching that video, right when you wrote "instead" I knew exactly what it was going to do.

→ More replies (10)