A Little Noise

February 6, 2013

Default user

Filed under: MySQL — snoyes @ 2:20 pm

It came up twice in two days: if you do not specify the user name when connecting, what gets picked?

The manual says:
“On Unix, most MySQL clients by default try to log in using the current Unix user name as the MySQL user name, but that is for convenience only.”
http://dev.mysql.com/doc/refman/5.6/en/user-names.html

“The default user name is ODBC on Windows or your Unix login name on Unix.”
http://dev.mysql.com/doc/refman/5.6/en/connecting.html

Let’s be a little more specific. The relevant section of code is in libmysql/libmysql.c

On Linux, we check the following in this order:
– if (geteuid() == 0), user is “root”
– getlogin()
– getpwuid(geteuid())
– environment variables $USER, $LOGNAME, $LOGIN
If none of those return non-NULL results, use “UNKNOWN_USER”

On Windows:
– environment variable $USER
If that’s not set, use “ODBC”.

I wondered why on Windows we check $USER but not $USERNAME. I gather that it’s an ODBC thing.

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress