MySQL 有没有办法知道你在mysql中的当前用户名?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19350275/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a way to know your current username in mysql?
提问by user1090729
I would like to know if there's a way for a mysql query to return the username of the user that issues the query.
我想知道是否有办法让 mysql 查询返回发出查询的用户的用户名。
Is this possible?
这可能吗?
采纳答案by scotru
Try the the CURRENT_USER()
function. This returns the username that MySQL used to authenticate your client connection. It is this username that determines your privileges.
试试这个CURRENT_USER()
功能。这将返回 MySQL 用于验证您的客户端连接的用户名。正是这个用户名决定了您的权限。
This may be different from the username that was sent to MySQL by the client (for example, MySQL might use an anonymous account to authenticate your client, even though you sent a username). If you want the username the client sent to MySQL when connecting use the USER()
function instead.
这可能与客户端发送到 MySQL 的用户名不同(例如,即使您发送了用户名,MySQL 也可能使用匿名帐户来验证您的客户端)。如果您想要客户端在连接时发送给 MySQL 的用户名,请改用该USER()
函数。
The value indicates the user name you specified when connecting to the server, and the client host from which you connected. The value can be different from that of CURRENT_USER().
该值表示您在连接到服务器时指定的用户名,以及您连接的客户端主机。该值可以与 CURRENT_USER() 的值不同。
http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_current-user
http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_current-user
回答by Petr Mensik
Try to run either
尝试运行
SELECT USER();
or
或者
SELECT CURRENT_USER();
It can sometimes be different, USER()will return by which login you attempted to authenticate and CURRENT_USER()will return how you were actually allowed to authenticate.
有时可能会有所不同,USER()将返回您尝试进行身份验证的登录名,而CURRENT_USER()将返回您实际允许进行身份验证的方式。
回答by Mihai
Use this query:
使用此查询:
SELECT USER();
Or
或者
SELECT CURRENT_USER;
回答by Plamen Nikolov
You can use:
您可以使用:
SELECT USER();
or
或者
SELECT CURRENT_USER();
See more here http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_current-user
在此处查看更多信息http://dev.mysql.com/doc/refman/5.0/en/information-functions.html#function_current-user
回答by Prashanthhh Kumarr
to print the current user who is using the database
打印正在使用数据库的当前用户
select user();
or
或者
select current_user();
回答by Ashish Karpe
You can also use : mysql> select user,host from mysql.user;
你也可以使用:mysql> select user,host from mysql.user;
+---------------+-------------------------------+
| user | host |
+---------------+-------------------------------+
| fkernel | % |
| nagios | % |
| readonly | % |
| replicant | % |
| reporting | % |
| reporting_ro | % |
| nagios | xx.xx.xx.xx |
| haproxy_root | xx.xx.xx.xx
| root | 127.0.0.1 |
| nagios | localhost |
| root | localhost |
+---------------+-------------------------------+
回答by heisenbug47
You can find the current user name with CURRENT_USER() function in MySQL.
您可以在 MySQL 中使用 CURRENT_USER() 函数查找当前用户名。
for Ex:
SELECT CURRENT_USER();
例如:
SELECT CURRENT_USER();
But CURRENT_USER()
will not always return the logged in user. So in case you want to have the logged in user, then use SESSION_USER()
instead.
但CURRENT_USER()
不会总是返回登录的用户。因此,如果您想要登录用户,请SESSION_USER()
改用。