【MySQL】MySQL刪除匿名使用者,保證登入安全

來源:互聯網
上載者:User

【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!已經成功刪除啦

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.