NAMEmatch_grantee(): Match an existing account based on user+host.
MySQL does not provide with identification of logged in accounts. It only provides with user + host:port combination within processlist. Alas, these do not directly map to accounts, as MySQL lists the host:port from which the connection is made, but not the (possibly wildcard) user or host.
This function matches a user+host combination against the known accounts, using the same matching method as the MySQL server, to detect the account which MySQL identifies as the one matching. It is similar in essence to CURRENT_USER(), only it works for all sessions, not just for the current session.
match_grantee(connection_user char(16) CHARSET utf8, connection_host char(70) CHARSET utf8) RETURNS VARCHAR(100) CHARSET utf8
- connection_user: user login (e.g. as specified by PROCESSLIST)
- connection_host: login host. May optionally specify port number (e.g. webhost:12345), which is discarded by the function. This is to support immediate input from as specified by PROCESSLIST.
Find an account matching the given use+host combination:
mysql> SELECT match_grantee('apps', '22.214.171.124:12345') AS grantee; +------------+ | grantee | +------------+ | 'apps'@'%' | +------------+