mysql 账户 禁止/开启远程访问
1、 禁用远程登录
root账户一般用于服务器,且远程部署的项目一般在服务器上是明文显示连接本地的127.0.0.1,且由于在安装mysql时大多程序猿都喜欢默认,导致root账户权限很大,密码很少,风险很高,一般都选择将其禁止远程访问
use mysql;
update user set host ='localhost' where user='root';
flush privileges;
如果此时提示root已经存在host为localhost的记录,不要慌,如果当初你是为了方便使用了
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' ;
flush privileges;
类似的操作,可以选择执行:
use mysql;
delete from user where host = '%' and user = 'root';
flush privileges;
重要: 这类的操作 是删除掉root 除host =‘localhost’ 以外 的记录 。
暴力操作,具体需要根据自家mysql配置来
2、开启远程登录权限
use mysql;
update user set host = "%" where user = "root";
flush privile