默认情况下mysql只允许本定登录,当需要远程登录访问操作时,需要开启允许远程连接。
一、开启远程方法
》》连接到本地mysql
》》进入msyql表
》》查看未开启远程连接前参数
方式一
使用root账户开启远程连接mysql数据库
grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;
flush privileges;
(释意:允许任何ip地址(%代表任意IP地址)用root账户和密码root访问此mysql server)
方式二
使用新建用户远程连接数据库
grant all privileges on *.* to 'kevin'@'%' identified by 'kevin' with grant option;
(提示:kevin kevin1234账户可以是未创建过的账户)
》》查看当前系统用户
》》远程连接成功
Tips:如果还不能远程连接开启防火墙即可:
二、关闭远程方法
》》使用root用户登录到数据库
》》选择mysql数据库
》》撤回权限
revoke all privileges on *.* from 'root'@'%';
》》删除授权用户并刷新权限
delete from user where User="root" and Host="%";
flush privileges;