zoukankan      html  css  js  c++  java
  • 开启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端口
     
     
  • 相关阅读:
    Jmeter性能测试 入门
    线程模型——什么是线程池、以及怎样正确地配置线程池
    在Spring Bean的生命周期中各方法的执行顺序
    @Autowired @Qualifier
    @Autowired还可以注入List和Map
    springcloud ribbon的 @LoadBalanced注解
    CAS实现SSO 单点登录
    Docker 概念-2
    你的JavaBean是否真的需要实现Serializable
    基于django的会议室预订系统
  • 原文地址:https://www.cnblogs.com/ccw869476711/p/10303325.html
Copyright © 2011-2022 走看看