MySQL - 19禁止ROOT用户远程登录
原创
©著作权归作者所有:来自51CTO博客作者szlsay的原创作品,请联系作者获取转载授权,否则将追究法律责任
为什么要禁止root远程登录
在实际工作中,公司的DBA都会设置禁止root用户远程登录,请问这是为什么?
- root是MySQL数据库的超级管理员,几乎拥有所有权限,一旦泄露后果非常严重;
- root是MySQL数据库的默认用户,所有人都知道,如果不禁止远程登录,可以针对root用户暴力破解密码。
实战案例
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 user, host from user;
+------------------+--------------+
| user | host |
+------------------+--------------+
| root | % |
| st | % |
| st0 | 192.0.12.111 |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
+------------------+--------------+
7 rows in set (0.00 sec)
mysql> update user set host='localhost' where user='st';
Query OK, 1 row affected (0.01 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> select user, host from user;
+------------------+--------------+
| user | host |
+------------------+--------------+
| root | % |
| st0 | 192.0.12.111 |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
| st | localhost |
+------------------+--------------+
7 rows in set (0.00 sec)
mysql> delete from user where user='root' and host='%';
Query OK, 1 row affected (0.02 sec)
mysql> select user, host from user;
+------------------+--------------+
| user | host |
+------------------+--------------+
| st0 | 192.0.12.111 |
| mysql.infoschema | localhost |
| mysql.session | localhost |
| mysql.sys | localhost |
| root | localhost |
| st | localhost |
+------------------+--------------+
6 rows in set (0.01 sec)
mysql>