欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  数据库

删除MySQL匿名用户

程序员文章站 2024-02-18 17:59:04
...

今天安装MySQL-5.1.62后,登陆进去查看用户,发现有四个 mysqlgt; select user,host from user;+------+--------------+| user

今天安装MySQL-5.1.62后,登陆进去查看用户,,发现有四个

mysql> select user,host from user;
+------+--------------+
| user | host |
+------+--------------+
| | MySQL-Server |
| root | MySQL-Server |
| | localhost |
| root | localhost |
+------+--------------+
4 rows in set (0.00 sec)

其中两个看不到用户名,通过正常的drop user无法删除
drop user ""@localhost
drop user ""@"MySQL-Server"
结果还是可以看得到,并没有被删除。


后来想到个方法,就是直接删除这个表的内容
mysql> delete from user where user='';
Query OK, 2 rows affected (0.01 sec)


mysql> select user,host from user;
+------+--------------+
| user | host |
+------+--------------+
| root | MySQL-Server |
| root | localhost |
+------+--------------+
2 rows in set (0.00 sec)


mysql> delete from user where host="MySQL-Server";
Query OK, 1 row affected (0.00 sec)


mysql> select user,host from user;
+------+-----------+
| user | host |
+------+-----------+
| root | localhost |
+------+-----------+
1 row in set (0.00 sec)


最后再刷新下就好了。
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)

相关阅读:

增加MySQL用户

MySQL用户管理

Linux下 MySQL 用户的管理

删除MySQL匿名用户