关闭linux防火墙能远程连接mysql_开启MySQL远程访问权限 允许远程连接(阿里云服务器)、linux关闭防火墙...

1.登陆mysql:mysql -u root -p

mysql> show databases;

+--------------------+

| Database |

+--------------------+

| information_schema |

| mysql |

| performance_schema |

| sys |

+--------------------+

4 rows in set (0.01 sec)

mysql> use mysql; # 切换到mysql数据库

Reading table information for completion of table and column names

You can turn off this feature to get a quicker startup with -A

Database changed

mysql> select host,user from user; # 查询user表

+-----------+---------------+

| host | user |

+-----------+---------------+

| % | root |

| localhost | mysql.session |

| localhost | mysql.sys |

+-----------+---------------+

5 rows in set (0.00 sec)

如果上述查询结果,root用户对应的host不为%,则修改用户权限

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root密码' WITH GRANT OPTION; # 修改权限

Query OK, 0 rows affected, 1 warning (0.00 sec)

mysql> FLUSH PRIVILEGES;

Query OK, 0 rows affected (0.00 sec)

或创建用户

mysql>insert into user (host,user,password) values('122.114.155.163','admin',password('ygpassword'));

mysql>FLUSH PRIVILEGES;

mysql>GRANT ALL PRIVILEGES ON *.* TO 'admin'@'122.114.155.163'IDENTIFIED BY 'ygpassword' WITH GRANT OPTION;

mysql>FLUSH PRIVILEGES;

完成。(如果连接不成功,继续执行下面操作)

2.阿里云的ECS需要手动添加安全组规则

612b5eea5dca4fa204addcbfa91c0816.png

3.关闭防火墙(关闭防火墙,就可以外部访问了。不受端口限制。生产环境,最好开启防火墙,开启部分端口。)

1.永久有效

1 开启: chkconfig iptables on2 关闭: chkconfig iptables off

2.即刻生效

1 开启: service iptables start2 关闭: service iptables stop

3.开启部分端口

1 vim /etc/sysconfig/iptables

添加想要开启的相关端口

1 -A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT2 -A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT3 -A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT4 -A INPUT -m state --state NEW -m tcp -p tcp --dport 8082 -j ACCEPT5 -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT

4.重启防火墙服务

1 service iptables restart

方法4:(腾讯云)

配置腾讯云服务器的安全组开放3306端口

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值