Saki's 研究记录

MySQL禁止root远程访问

字数统计: 113阅读时长: 1 min
2021/11/23

查看用户信息

1
2
3
4
5
6
7
8
9
10
11
12
use mysql;
select host,user from user;
+------------------+-----------+-----------------------+
| user | host | plugin |
+------------------+-----------+-----------------------+
| root | % | caching_sha2_password |
| mysql.infoschema | localhost | caching_sha2_password |
| mysql.session | localhost | caching_sha2_password |
| mysql.sys | localhost | caching_sha2_password |
| root | localhost | caching_sha2_password |
+------------------+-----------+-----------------------+
5 rows in set (0.04 sec)

修改用户host属性

修改root用户的host属性,确保其为localhost,这表示只能本地访问(%表示可以远程访问):

1
update user set host = 'localhost' where user = 'root' and host = '%';

如果已有host为’%’的root记录,则删除:

1
drop user 'root'@'%';

Done.

CATALOG
  1. 1. 查看用户信息
  2. 2. 修改用户host属性