Declaration
CURRENT_USER()
Description
In OceanBase AI Database, a login account is defined by a combination of a username and a hostname. This function returns a string representing the login account name, using the utf8mb4 character set.
When logging in to OceanBase AI Database, the database performs a match between the username and the hostname. For example, if you create two users testUser@192.168.%.% and testUser@192.%.%.%, you can query the mysql.USER table for the following users:
obclient> SELECT USER,HOST FROM mysql.USER ORDER BY USER,HOST;
+------------+----------------+
| user | host |
+------------+----------------+
...
| testUser | 192.%.%.% |
| testUser | 192.168.%.% |
...
+------------+----------------+
In a user tenant, different combinations of username and hostname can have different privileges and are recognized as different users during matching. For example, you can grant the SELECT and UPDATE privileges to testUser@192.168.%.%, and grant 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 '******';
Log in to OceanBase AI Database as the test 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
After deleting test@192.168.%.%, connect to OceanBase AI 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
View the current database login user.
obclient> SELECT CURRENT_USER();
+----------------+
| CURRENT_USER() |
+----------------+
| root@% |
+----------------+
1 row in set