MySqlConnector icon indicating copy to clipboard operation
MySqlConnector copied to clipboard

Use `Environment.UserName` as the default user name

Open bgrainger opened this issue 3 years ago • 1 comments
trafficstars

This SO user (https://stackoverflow.com/questions/71742985/how-to-compose-a-connection-string-without-login-credentials-net-mysqlconnector) expects MySqlConnectionStringBuilder.UserID to default to the current Unix user when connecting via a Unix socket. That is how some other MySQL client libraries behave:

https://dev.mysql.com/doc/refman/8.0/en/user-names.html

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.

https://dev.mysql.com/doc/c-api/8.0/en/mysql-real-connect.html

The user argument contains the user's MySQL login ID. If user is NULL or the empty string "", the current user is assumed. Under Unix, this is the current login name.

The workaround is to manually set MySqlConnectionStringBuilder.UserID to Environment.UserName or a hard-coded user name.

bgrainger avatar Apr 12 '22 14:04 bgrainger

This could be a breaking change if there are some MySQL Servers that accept an empty username (although that seems unlikely). Still, to avoid unexpected behaviour, this implicit username could only be used for Unix socket connections (which is likely the most common scenario anyway).

bgrainger avatar Apr 12 '22 15:04 bgrainger