信息发布→ 登录 注册 退出

如何设置mysql允许外部连接访问

发布时间:2026-01-11

点击量:

1.设置mysql允许外部连接访问(授权):

grant all privileges on *.* to root@'%' identified by '123456' with grant option;
flush privileges;

例子:
查询mysql用户权限、授权、刷新使生效

select host, user from user;
grant all privileges on *.* to root@'%' identified by '密码' with grant option;
flush privileges;

指定ip地址授权:ip地址指的是连接时失败报错1130弹出的地址

grant all privileges on *.* to root@'ip地址' identified by '密码' with grant option;
flush privileges;

没有权限:

连接成功:

注:不管使用navicat还是命令窗口,都是去操作mysql库中的user
1,可以使用navicat工具进入到数据库中mysql库执行语句;

2,使用命令执行,进入到命令窗口,登录到mysql服务器进入到mysql库(use mysql)中,执行以上授权语句即可。

连接服务器:

mysql -u root -p

进入mysql数据库:

use mysql;

查看user表中的数据:

select Host, User,Password from user;

第一种:修改user表的方法
修改user表中的Host:

update user set Host='%' where User='root';

第二种:授权的方法:将上面代码换为授权的代码即可;

grant all privileges on *.* to root@'%' identified by '密码' with grant option;

最后刷新一下:

flush privileges;

2.设置mysql允许外部连接访问(修改表的方法):

update user set Host='%' where User='root';
flush privileges;
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!