mysql实现远程连接
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
本文来自博客园,作者:公子初心,转载请注明原文链接:https://www.cnblogs.com/ixuhui/p/15923490.html