CURRENT_USER
Syntax
CURRENT_USER()
Description
seekdb 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 seekdb, seekdb matches the username and hostname. For example, if you create two users testUser@11.162.%.% and demoUser@11.162.%.%, you can query the mysql.USER table to find the following users:
SELECT USER,HOST FROM mysql.USER ORDER BY USER,HOST;
+------------+----------------+
| user | host |
+------------+----------------+
...
| testUser | 11.162.%.% |
| demoUser | 11.162.%.% |
...
+------------+----------------+
In seekdb, different combinations of usernames and hostnames can have different privileges. These combinations are recognized as different users during matching. For example, you can grant the SELECT and UPDATE privileges to 'testUser'@'11.162.%.%' and the SELECT privilege to 'demoUser'@'11.162.%.%'.
-- Grant the UPDATE and SELECT privileges to the user 'testUser'@'11.162.%.%'
GRANT UPDATE, SELECT ON *.* TO 'testUser'@'11.162.%.%' identified by '********';
-- Refresh and make the user privileges effective
FLUSH PRIVILEGES;
-- Grant the SELECT privilege to the user 'demoUser'@'11.162.%.%'
GRANT SELECT ON *.* TO 'demotUser'@'11.162.%.%' identified by '*******';
-- Refresh and make the user privileges effective
FLUSH PRIVILEGES;
After you log in to seekdb as the testUser user, execute CURRENT_USER(). The result is as follows:
mysql -h11.162.xxx.xxx -P2881 -utestUser -p********
SELECT CURRENT_USER();
+---------------------+
| CURRENT_USER() |
+---------------------+
| testUser@11.162.%.% |
+---------------------+
1 row in set (0.001 sec)
After you delete the testUser'@'11.162.%.% user, log in to seekdb as the testUser user again. The result is as follows:
DROP USER DROP USER 'testUser'@'11.162.%.%';
mysql -h11.162.xxx.xxx -P2881 -utestUser -p*******
ERROR 1045 (42000): Access denied for user 'testUser'@'xxx.xxx.xxx.xxx' (using password: YES)
Examples
Query the login user of the current database.
Example: Connect to seekdb as the demoUser user. The result is as follows:
mysql -h11.162.xxx.xxx -P2881 -udemoUser -p********
+---------------------+
| CURRENT_USER() |
+---------------------+
| demoUser@11.162.%.% |
+---------------------+
1 row in set (0.000 sec)