← Back to team overview

maria-developers team mailing list archive

Re: Updating MySQL Client Protocol: Possible and still be backward compatible?

 

Hi, Adam!

On Sep 03, Adam Scott wrote:
> Is it possible to have mysql client protocol return the OS username and
> allow the protocol to backward compatible?
> 
> Looking to see if reasonable to provide same functionality as Oracle does
> with
> 
> select sys_context( 'userenv', 'os_user' ) from dual;

Yes, and there is no need to change the protocol. Since 10.0 it
supports arbitrary "connection attributes". You need to modify your
clients (or libmysqlclient, if you prefer that) to send the OS username,
like this:

  mysql_options4(&mysql, MYSQL_OPT_CONNECT_ATTR_ADD, "os_user", "serg");

(but with geteuid(), etc instead of hard-coded name), and then you can
do

MariaDB [test]> select * from performance_schema.session_connect_attrs;
+----------------+-----------------+------------+------------------+
| PROCESSLIST_ID | ATTR_NAME       | ATTR_VALUE | ORDINAL_POSITION |
+----------------+-----------------+------------+------------------+
|              2 | _os             | Linux      |                0 |
|              2 | _client_name    | libmysql   |                1 |
|              2 | _pid            | 2387       |                2 |
|              2 | _client_version | 10.0.14    |                3 |
|              2 | _platform       | x86_64     |                4 |
|              2 | program_name    | mysql      |                5 |
|              2 | os_user         | serg       |                6 |
+----------------+-----------------+------------+------------------+
7 rows in set (0.01 sec)

Regards,
Sergei



References