您的位置:首页 > 数据库 > MySQL

mysql 5.5 任意用户不加密码均能登录解决方法

2017-04-14 10:17 387 查看
mysql版本5.5:

在添加用户及赋予权限的过程中,发现用任意用户不需要添加任何密码均能登录,(而加了密码却不能登录),如:

# mysql -u monitorshowsssaaaaaaaaaa 

Welcome to the MySQL monitor.  Commands end with ; or \g.

Your MySQL connection id is 327

Server version: 5.5.13-rel20.4-log Percona Server with XtraDB (GPL), Release rel20.4, Revision 138

Copyright (c) 2000, 2010, 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)

但权限只限于test的数据库。

以root用户登录,查看user表:

mysql> select user,host,password from mysql.user;

+-----------------+----------------------------+-------------------------------------------+

| user            | host                       | password                                  |

+-----------------+----------------------------+-------------------------------------------+

| root            | localhost                  | *00EEFBA06C5B79E87B09C3713FCE2CB9965A1DFE |

| root            | HZ-D15-02-geyan09120.getui |                                           |

| root            | 127.0.0.1                  |                                           |

| root            | ::1                        |                                           |

|                 | localhost                  |                                           |

|                 | HZ-D15-02-geyan09120.getui |                                           |

| gexingeyanmdp   | %                          | *186A5CCB6AC9C6589E5C63913AA1196976131B64 |

| monitor         | %                          | *6F026364683BA7E8AF7ECCCF1BED682117388698 |

+-----------------+----------------------------+-------------------------------------------+

发现有两个空的user,且password也为空。

将其删除:

mysql> delete from mysql.user where user='';

Query OK, 2 rows affected (0.00 sec)

并刷新:

mysql> flush privileges;

Query OK, 0 rows affected (0.00 sec)

然后再重新登:

# mysql -u monitorshowsssaaaaaaaaaa 

ERROR 1045 (28000): Access denied for user 'monitorshowsssaaaaaaaaaa'@'localhost' (using password: NO)

发现会有报错,恢复正常。

注:

空用户的话,表示任意用户都可以访问;

他所对应的密码为空,所以,如果输入密码反而不能登陆;

删除空用户后需要刷新。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: