Home  >  Article  >  Database  >  How to query the currently logged in user in mysql

How to query the currently logged in user in mysql

WBOY
WBOYOriginal
2022-05-16 17:41:448857browse

Method: 1. Use the USER() function to return the current user name and host name of the connection, with the syntax "select user()"; 2. Use the "currrent_user()" function to display the current login user's corresponding One in the user table, syntax "select current_user()".

How to query the currently logged in user in mysql

The operating environment of this tutorial: centos 7 system, mysql8.0.22 version, Dell G3 computer.

How does mysql query the currently logged in user

  • The user() function returns the current user name and host name of the MySQL connection. It is used to display the currently logged in user name and its corresponding host.

  • currrent_user() is used to display which one in the user table the currently logged in user corresponds to.

user(), one thing to note is that it is a function, not part of the SQL statement (which means it cannot be used in other databases).

We can help user get help from this function.

Teach you how to view the currently logged in user on mysql

You can see that the usage method is select user();

(not case sensitive)

select user();

Teach you how to check the current logged in user on mysql

Need to explain: root@localhost

How to query the currently logged in user in mysql

root refers to the user we are currently logged in, localhost refers to the local host (which database server you log in to). If you have a network foundation, you must know that it points to the loopback address 127.0.0.1.

Another way is to get the current user name through current_user.

select current_user();

PS: The brackets can be omitted

How to query the currently logged in user in mysql

The example is as follows:

mysql> select user();
+----------------------+
| user()               |
+----------------------+
| test@192.168.203.132 |
+----------------------+
1 row in set (0.00 sec)
mysql> select current_user();
+------------------+
| current_user()   |
+------------------+
| test@192.168.%.% |
+------------------+
1 row in set (0.00 sec)

Recommended learning: mysql video tutorial

The above is the detailed content of How to query the currently logged in user in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn