MySqlConnector
MySqlConnector copied to clipboard
Use `Environment.UserName` as the default user name
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
userargument contains the user's MySQL login ID. IfuserisNULLor 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.
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).