2012-07-05 52 views
1

是否需要将MySQL用户添加到MySQL“系统”中?是否需要将MySQL用户添加到MySQL“系统”?

我在学习MySQL基础知识,但这个问题刚刚出现。这是为什么:

:~$ mysql -u johndoe 
Welcome to the MySQL monitor. Commands end with ; or \g. 
Your MySQL connection id is 50 
Server version: 5.5.24-0ubuntu0.12.04.1 (Ubuntu) 

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved. 

Oracle is a registered trademark of Oracle Corporation and/or its 
affiliates. Other names may be trademarks of their respective 
owners. 

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. 

mysql> SELECT User(); 
+-------------------+ 
| User()   | 
+-------------------+ 
| [email protected] | 
+-------------------+ 
1 row in set (0.00 sec) 

mysql> quit 
Bye 

当然,我没有设置一个名为johndoe的用户,但似乎我可以用任何用户名输入mysql。我并不是说我会看到任何数据库,因为它可能没有设置任何数据库,例如johndoe可以做些事情。

所以我的问题最后是:这是真的还是我看到它是错误的?

+1

如果你可以用随机用户登录mysql,这意味着你正在用'--skip-grant-tables'运行你的服务器。 – golja 2012-07-06 00:39:29

+0

不是。你可以看到@SelloLekgothoane答案,或者按照以下链接:[function_current-user](http://dev.mysql.com/doc/refman/5.1/en/information-functions.html#function_current-user),[function_user] (http://dev.mysql.com/doc/refman/5.1/en/information-functions.html#function_user)和[account-activity-auditing](http://dev.mysql.com/doc/refman/ 5.1/EN /帐户 - 活性 - auditing.html)。 – Miguel 2012-07-06 04:06:33

+0

您也可以关注[此链接](http://dev.mysql.com/doc/refman/5.1/en/default-privileges.html),非常明确。确实是 – Miguel 2012-07-06 14:34:36

回答

1

实际上,由于用户“johndoe @ localhost”不存在,MySQL以匿名用户(''@ localhost)连接了你。运行“SELECT CURRENT_USER()”,你会明白我的意思,同样,如果你检查mysql数据库中的用户表,你会发现host ='localhost'和user =''的行。

+0

。谢谢! – Miguel 2012-07-06 03:47:05

+0

Miguel的头脑将问题标记为答案并给予Sello他应得的答案? – Namphibian 2012-07-06 05:25:36

+0

对不起,我不知道我需要这样做。现在我认为它是正确的:标记为已回答的问题,Sello得到了他的观点。 – Miguel 2012-07-06 12:11:54

相关问题