mysql: whoami?

陌路散爱 提交于 2019-12-21 03:09:31

问题


Is there a whoami-like function in mysql?

I'm connecting to the mysql command line from a remote host. I'm not sure if my ip address is resolving to a domain name or not. I would like to see something like

mysql> whoami;
+----------------------------------+
| User     | Host                  |
+----------------------------------+
| username | resolved.hostname.com |
+----------------------------------+
1 row in set (0.00 sec)

or

mysql> whoami;
+------------------------+
| User     | Host        |
+------------------------+
| username | 22.66.88.44 |
+------------------------+
1 row in set (0.00 sec)

回答1:


You can use the CURRENT_USER and USER functions as follows:

SELECT CURRENT_USER();

SELECT USER();

CURRENT_USER shows who you are authenticated as, while USER shows who you tried to authenticate as.

See the MySQL manual for more information.




回答2:


If you are using mysql command line utility then try \s command:

mysql> \s
--------------
mysql  Ver 14.12 Distrib 5.0.67, for suse-linux-gnu (i686) using readline 5.2

Connection id:          519
Current database:
Current user:           admin@localhost
.........
Server version:         5.0.67 SUSE MySQL RPM
.........



回答3:


Just do a...

select user,host from mysql.user;

Should show you what you want.



来源:https://stackoverflow.com/questions/2766359/mysql-whoami

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!