Linux普通用户不需要密码就能登录MySQL?
1、Linux普通用户
[zhou@zhou ~]$ mysql
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 5.6.51 MySQL Community Server (GPL)
Copyright © 2000, 2021, 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>
2、Root用户
[root@zhou zhou]# mysql
ERROR 1045 (28000): Access denied for user ‘root’@‘localhost’ (using password: NO)
这样是否会造成数据库安全问题?如何解决?
1、查询数据库用户
mysql> select user,host from mysql.user;#查询数据库用户
±-------±-------------+
| user | host |
±-------±-------------+
| root | 127.0.0.1 |
| blog | 192.168.16.% |
| zhou | 192.168.16.% |
| | localhost |#这里有个空白可登录的用户
| root | localhost |
±-------±-------------+
5 rows in set (0.00 sec)
发现有空白用户,是允许本地主机直接登录的
2、删除空白用户
mysql> drop user ‘’@‘localhost’;
Query OK, 0 rows affected (0.00 sec)
mysql> select user,host from mysql.user;#检查是否删除
±-------±-------------+
| user | host |
±-------±-------------+
| root | 127.0.0.1 |
| blog | 192.168.16.% |
| zhou | 192.168.16.% |
| root | localhost |
±-------±-------------+
4 rows in set (0.00 sec)
3、校验是否成功
[zhou@zhou ~]$ mysql
ERROR 1045 (28000): Access denied for user ‘zhou’@‘localhost’ (using password: NO)
搞定,收工,我的MySQL版本是5.6.51,安装成功自动创建了这么一个用户,安全起见,检查一下你的数据库有没有这样的空白用户吧!