2012-07-05 58 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