开启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需要手动添加安全组规则
3.关闭防火墙(关闭防火墙,就可以外部访问了。不受端口限制。生产环境,最好开启防火墙,开启部分端口。)
1.永久有效
1 开启: chkconfig iptables on 2 关闭: chkconfig iptables off
2.即刻生效
1 开启: service iptables start 2 关闭: service iptables stop
3.开启部分端口
1 vim /etc/sysconfig/iptables
添加想要开启的相关端口
1 -A INPUT -m state --state NEW -m tcp -p tcp --dport 6379 -j ACCEPT 2 -A INPUT -m state --state NEW -m tcp -p tcp --dport 8080 -j ACCEPT 3 -A INPUT -m state --state NEW -m tcp -p tcp --dport 8081 -j ACCEPT 4 -A INPUT -m state --state NEW -m tcp -p tcp --dport 8082 -j ACCEPT 5 -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
4.重启防火墙服务
1 service iptables restart
方法4:(腾讯云)
配置腾讯云服务器的安全组开放3306端口
版权声明:本文为ccw869476711原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。