Syntax
CURRENT_USER()
Purpose
OceanBase Database defines a login account by combining the username and hostname. This function returns the string of the login account name, using the utf8mb4 character set.
When you log in to OceanBase Database, OceanBase Database will match the username and hostname. For example, if you create two users testUser@192.168.%.% and testUser@192.%.%.%, you can query the mysql.USER table to find the following users:
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 username and hostname can have different privileges. These combinations are also recognized as different users during matching. For example, you can grant the SELECT and UPDATE privileges to testUser@192.168.%.% and the SELECT privilege to testUser@192.%.%.%.
obclient> GRANT SELECT,UPDATE ON *.* TO testUser@192.168.%.% IDENTIFIED BY '******';
obclient> GRANT SELECT ON *.* TO testUser@192.%.%.% IDENTIFIED BY '******';
After logging in to OceanBase Database as the test user, 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
After deleting the test@192.168.%.% user, connect to OceanBase Database again as the test 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
Query the login user of the current database.
obclient> SELECT CURRENT_USER();
+----------------+
| CURRENT_USER() |
+----------------+
| root@% |
+----------------+
1 row in set
