mysql实现远程连接

Posted on 2022-03-15 16:09  君子不卿  阅读(1381)  评论(0编辑  收藏  举报

1.开启远程mysql数据库访问

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'youpassword' WITH GRANT OPTION;

2.操作完后切记执行以下命令刷新权限

FLUSH PRIVILEGES;
mysql默认情况下,只允许localhost连接,如果需要外部IP连接到mysql,需要向mysql数据库里的“user”表里添加相关授权。 例如:让newuser用户使用newpwd密码从IP:192.168.1.3主机链接到mysql服务器
具体步骤:
GRANT ALL PRIVILEGES ON . TO 'newuser'@'192.168.1.3' IDENTIFIED BY 'newpwd' WITH GRANT OPTION; mysql>flush privileges;

3.再次查询mysql访问授权是否开启

select * from mysql.user where user='root'\G

4.防火墙开放mysql的3306端口

firewall-cmd --zone=public--add-port=3306/tcp --permanent

5.重启防火墙

systemctl restart firewalld.service

6.查询防火墙开放的端口

firewall-cmd --list-ports

Copyright © 2024 君子不卿
Powered by .NET 9.0 on Kubernetes

//评论