Syntax
CURRENT_USER()
Purpose
OceanBase Database authenticates the logon account by using the username and host name in combination. You can call this function to return the username as a utf8mb4 string.
When you log on to OceanBase Database, OceanBase Database matches the username and host name. In the following example, two users are created: testUser@192.168.%.% and testUser@192.%.%.%. They can be queried in the mysql.user table.
obclient> SELECT user,host FROM mysql.user ORDER BY user,host;
+------------+----------------+
| user | host |
+------------+----------------+
...
| testUser | 192.%.%.% |
| testUser | 192.168.%.% |
...
+------------+----------------+
In a MySQL tenant, different combinations of usernames and host names are identified as different users. They can be granted different privileges. In the following example, the SELECT and UPDATE privileges are granted to the testUser@192.168.%.% user, and the SELECT privilege is granted to the testUser@192.%.%.% user.
obclient> GRANT SELECT,UPDATE ON *.* TO testUser@192.168.%.% IDENTIFIED BY '******';
obclient> GRANT SELECT ON *.* TO testUser@192.%.%.% IDENTIFIED BY '******';
Log on to OceanBase Database as the testUser user, and execute CURRENT_USER(). The result is as follows:
[admin@hostname ~]$ obclient -hxxx.xx.xxx.xxx -Pxxxx -utest***@xxx#xxx -p
obclient> SELECT CURRENT_USER();
+----------------------+
| CURRENT_USER() |
+----------------------+
| testUser@192.168.%.% |
+----------------------+
1 row in set
Delete the testUser@192.168.%.% user, connect to OceanBase Database by using the testUser user, and execute CURRENT_USER(). The result is as follows:
obclient> DROP USER 'testUser'@'192.168.%.%';
obclient> \q
Bye
[admin@hostname ~]$ obclient -hxxx.xx.xxx.xxx -Pxxxx -utest***@xxx#xxx -p
obclient> SELECT CURRENT_USER();
+----------------------+
| CURRENT_USER() |
+----------------------+
| testUser@192.%.%.% |
+----------------------+
1 row in set
Examples
View the current logon user.
obclient> SELECT CURRENT_USER();
+----------------+
| CURRENT_USER() |
+----------------+
| root@% |
+----------------+
1 row in set