Syntax
CURRENT_USER()
Notes
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: test@192.168.%.% and test@192.%.%.%. They can be queried in the mysql.USER table:
obclient> SELECT USER,HOST FROM mysql.USER ORDER BY USER,HOST;
+------------+----------------+
user host
+------------+----------------+
...
test 192.%.%.%
test 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 test@192.168.%.% user, and the SELECT privilege is granted to the test@192.%.%.% user.
obclient> GRANT SELECT,UPDATE ON *.* TO test@192.168.%.% IDENTIFIED BY 'XXXXXX';
obclient> GRANT SELECT ON *.* TO test@192.%.%.% IDENTIFIED BY 'XXXXXX';
Log on to OceanBase Database as the test user, and execute CURRENT_USER(). Sample result:
[admin@hostname ~]$ obclient -hxxx.xx.xxx.xxx -Pxxxx -utest@xxx#xxx -p
obclient> SELECT CURRENT_USER();
+----------------------+
user()
+----------------------+
test@192.168.%.%
+----------------------+
1 row in set (0.00 sec)
Delete the test@192.168.%.% user, connect to OceanBase Database by using the test user, and execute CURRENT_USER(). Sample result:
obclient> DROP USER 'test'@'192.168.%.%';
obclient> \q
Bye
[admin@hostname ~]$ obclient -hxxx.xx.xxx.xxx -Pxxxx -utest@xxx#xxx -p
obclient> SELECT CURRENT_USER();
+----------------------+
user()
+----------------------+
test@192.%.%.%
+----------------------+
1 row in set (0.00 sec)
Examples
View the current logon user:
obclient> SELECT CURRENT_USER();
+----------------+
CURRENT_USER()
+----------------+
root@%
+----------------+
1 row in set (0.00 sec)