在Mysql中,有两个函数,一个是user(),一个是current_user();
user()是用来显示当前登陆的用户名与它对应的host,帮助文档是这样描述的:
Returns the current MySQL user name and host name as a string in the
utf8 character set.
currrent_user()是用来显示当前登陆用户对应在user表中的哪一个,帮助文档是这样描述的:
Returns the user name and host name combination for the MySQL account
that the server used to authenticate the current client. This account
determines your access privileges. The return value is a string in the
utf8 character set.
总结:user()显示当前登录的用户;current_user()显示当前登录的用户匹配的系统中的用户
举例:
mysql> select user(),current_user,system_user();
+-------------------+--------------+-------------------+
| user() | current_user | system_user() |
+-------------------+--------------+-------------------+
| smartdb@localhost | smartdb@% | smartdb@localhost |
+-------------------+--------------+-------------------+
1 row in set (0.00 sec)
user():当前登录的用户
current_user():匹配系统创建的用户
| 留言与评论(共有 0 条评论) “” |