参考文章:点击跳转
现象描述
任意用户可登录MySQL数据库。如下面操作。会发现,此时登录后无法查看到正常的全部数据库,只能看到系统默认的测试数据库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)
分析
正常登录该数据库,查看用户表,第四列里面,host为localhost,用户为空,密码为空。导致在本地登陆的时候除了root的账户外,其他账号不需要密码即可登陆,并且影响host为%的用户登陆。文章来源:https://www.toymoban.com/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>
解决
删除空用户。然后重启数据库。不重启数据库不生效。文章来源地址https://www.toymoban.com/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)
//不重启数据库不生效。重启后生效。
else@linux-ctc7:~> mysql -u else ---重启数据库前仍可登录
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 ---重启数据库后,root用户无法直接连接。
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
else@linux-ctc7:~> mysql -u else ---重启数据库后,普通用户无法直接连接。
ERROR 1045 (28000): Access denied for user 'else'@'localhost' (using password: NO)
到了这里,关于mysql用户可免密码登录问题处理解决的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!