參考文章:點(diǎn)擊跳轉(zhuǎn)
現(xiàn)象描述
任意用戶可登錄MySQL數(shù)據(jù)庫。如下面操作。會(huì)發(fā)現(xiàn),此時(shí)登錄后無法查看到正常的全部數(shù)據(jù)庫,只能看到系統(tǒng)默認(rèn)的測試數(shù)據(jù)庫test和信息庫infomation_schema。
else@linux-ctc7:~> mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 5.1.73-community MySQL Community Server (GPL)
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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| test |
+--------------------+
2 rows in set (0.00 sec)
分析
正常登錄該數(shù)據(jù)庫,查看用戶表,第四列里面,host為localhost,用戶為空,密碼為空。導(dǎo)致在本地登陸的時(shí)候除了root的賬戶外,其他賬號不需要密碼即可登陸,并且影響host為%的用戶登陸。文章來源:http://www.zghlxwxcb.cn/news/detail-637494.html
else@linux-ctc7:~> mysql -uroot -pmysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 5.1.73-community MySQL Community Server (GPL)
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> 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 host,user,password from user;
+------------+------+-------------------------------------------+
| host | user | password |
+------------+------+-------------------------------------------+
| % | root | *E74858DB86EBA20BC33D0AECAE8A8108C56B17FA |
| linux-ctc7 | root | |
| 127.0.0.1 | root | |
| localhost | | |
| linux-ctc7 | | |
+------------+------+-------------------------------------------+
5 rows in set (0.00 sec)
mysql>
解決
刪除空用戶。然后重啟數(shù)據(jù)庫。不重啟數(shù)據(jù)庫不生效。文章來源地址http://www.zghlxwxcb.cn/news/detail-637494.html
mysql> select host,user from user;
+------------+------+
| host | user |
+------------+------+
| % | root |
| 127.0.0.1 | root |
| linux-ctc7 | |
| linux-ctc7 | root |
| localhost | |
| localhost | test |
+------------+------+
6 rows in set (0.00 sec)
mysql> delete from user where host='localhost' and user='';
Query OK, 1 row affected (0.00 sec)
mysql> delete from user where host='linux-ctc7' and user='';
Query OK, 1 row affected (0.00 sec)
//不重啟數(shù)據(jù)庫不生效。重啟后生效。
else@linux-ctc7:~> mysql -u else ---重啟數(shù)據(jù)庫前仍可登錄
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 23
Server version: 5.1.73-community MySQL Community Server (GPL)
Copyright (c) 2000, 2013, Oracle and/o 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>
linux-ctc7:/etc/init.d # ./mysql stop
Shutting down MySQL.. done
linux-ctc7:/etc/init.d # ps -ef|grep mysql
root 5561 5490 0 09:03 pts/1 00:00:00 grep mysql
linux-ctc7:/etc/init.d # ./mysql start
Starting MySQL. done
linux-ctc7:/etc/init.d # mysql ---重啟數(shù)據(jù)庫后,root用戶無法直接連接。
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
else@linux-ctc7:~> mysql -u else ---重啟數(shù)據(jù)庫后,普通用戶無法直接連接。
ERROR 1045 (28000): Access denied for user 'else'@'localhost' (using password: NO)
到了這里,關(guān)于mysql用戶可免密碼登錄問題處理解決的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!