博客地址已遷往 www.virtclouds.com
原文地址 http://www.virtclouds.com/538.html
很多MySQL程序都會帶有匿名登錄的功能。
在剛剛安裝完MySQL之后,就能夠登錄數據庫啦。
這對於平時使用MySQL來說也基本沒有什么,可是假設我們想部署數據庫的時候。這樣的登錄方式式絕對不能存在的!試想一下,假設你的數據庫隨便就能夠進入的話,我想你一定會在半夜收到電話,說數據出問題啦!
以下介紹一下刪除匿名用戶的方式:
首先使用命令進入數據庫
[root@localhost raul]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 3 Server version: 5.1.73 Source distribution Copyright (c) 2000, 2013, 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
mysql> use mysql Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed
刪除之前我們先查看一下數據庫的用戶表,看看用戶的存在情況
mysql> select user, host from user; +------+-----------------------+ | user | host | +------+-----------------------+ | root | 127.0.0.1 | | | localhost | | root | localhost | | | localhost.localdomain | | root | localhost.localdomain | +------+-----------------------+ 5 rows in set (0.00 sec)
我們看到啦,在user這一列有的行是空的。這就是那個匿名用戶啦~。在這一步我們已經找到匿名用戶啦,剩下的操作就是刪除掉這個用戶,保證登錄安全
mysql> delete from user where user=''; Query OK, 2 rows affected (0.00 sec)
此時mysql運行的狀態顯示我們刪除了兩行數據,然后運行一邊查詢命令,確認一下是不是真的刪除成功啦啊
mysql> select user, host from user; +------+-----------------------+ | user | host | +------+-----------------------+ | root | 127.0.0.1 | | root | localhost | | root | localhost.localdomain | +------+-----------------------+ 3 rows in set (0.00 sec)
OK!已經成功刪除啦
