【MySQL】MySQL刪除匿名使用者,保證登入安全
許多MySQL程式都會帶有匿名登入的功能。在剛剛安裝完MySQL之後,就可以登入資料庫啦。
這對於平時使用MySQL來說也基本沒有什麼,但是如果我們想部署資料庫的時候,這種登入方式式絕對不能存在的!試想一下,如果你的資料庫隨便就可以進入的話,我想你一定會在半夜收到電話,說資料出問題啦!
下面介紹一下刪除匿名使用者的方式:
首先使用命令進入資料庫
[root@localhost raul]# mysql -u root -pEnter password: Welcome to the MySQL monitor. Commands end with ; or \g.Your MySQL connection id is 3Server version: 5.1.73 Source distributionCopyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
然後切換資料庫,進入我們需要操作的資料庫mysql
mysql> use mysqlReading table information for completion of table and column namesYou can turn off this feature to get a quicker startup with -ADatabase 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!已經成功刪除啦