但如果MySQL要作为数据库提供给Web服务器使用的话,忽略这个匿名用户的代价可能相当惨重。因为在默认设置下,这个匿名用户在localhost上几乎拥有和root一样的权限。很可能因为访问者上传一个PHP文件,用这个PHP文件创建一个新用户,并给他一个较高的权限,然后用这个新用户连接到服务器的MySQL,对该服务器的MySQL进行管理。
删除命令如下:
复制代码 代码如下:
MySQL>UPDATE user set password=PASSWORD('your password') where user='';
MySQL>FLUSH PRIVILEGES;
mysql中删除匿名用户详细步骤如下:
[root@sample ~]#mysql -u root -p ← 通过密码用root登录
Enter password: ← 在这里输入密码
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7 to server version: 4.1.20
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>select user,host from mysql.user; ← 查看用户信息
+------+----------------------------+
| user | host |
+------+----------------------------+
| | localhost |
| root | localhost |
| | sample.centospub.com |
| root | sample.centospub.com |
+------+----------------------------+
4 rows in set (0.02 sec)
mysql> delete from mysql.user where user=''; ← 删除匿名用户
Query OK, 2 rows affected (0.17 sec)
mysql> select user,host from mysql.user; ← 查看用户信息
+------+----------------------------+
| user | host |
+------+----------------------------+
| root | localhost |
| root | sample.centospub.com |
+------+----------------------------+
2 rows in set (0.00 sec)
mysql> exit ← 退出MySQL服务器
Bye