zoukankan      html  css  js  c++  java
  • 如何解决远程连接mysql出现Can’t connect to MySQL server on (111 “Connection refused”)的问题

    如何解决远程连接mysql出现Can’t connect to MySQL server on (111 “Connection refused”)的问题

    开放Mysql的远程连接

    在服务器上登录mysql,然后执行以下的命令。

    登录mysql:

    1. /usr/local/mysql-5.6/bin/mysql -u root -p

    执行赋权的命令:

    1. MySQL> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
    1. MySQL> flush privileges;

    也可以直接重启mysql。

    1. /usr/local/mysql-5.6/support-files/mysql.server restart

    远程连接Mysql

    在本地连接mysql,我们可以使用mysql workbench,这是一款英文的mysql的客户端。

    连接的时候出现错误:Can't connect to MySQL server on Ip地址 (111 "Connection refused")。

    检查防火墙

    先检查防火墙的3306端口是不是放开了。这台服务器使用的是iptables,打开iptables,配置3306端口。

    1. vi /etc/sysconfig/iptables
    2.  
    3. # Firewall configuration written by system-config-firewall
    4. # Manual customization of this file is not recommended.
    5. *filter
    6. :INPUT ACCEPT [0:0]
    7. :FORWARD ACCEPT [0:0]
    8. :OUTPUT ACCEPT [0:0]
    9. -A INPUT -p tcp -m tcp --dport 10100:10180 -j ACCEPT
    10. -A INPUT -p tcp -m tcp --dport 21 -j ACCEPT
    11. -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
    12. -A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT
    13. -A INPUT -j REJECT reject-with icmp-host-prohibited
    14. -A FORWARD -j REJECT reject-with icmp-host-prohibited
    15. COMMIT

    重启防火墙

    1. /etc/init.d/iptables restart

    检查my.cnf

    在my.cnf的配置文件中,有参数控制它是否运行在网络上。例如查看这个my.cnf。

    1. vi /usr/local/mysql-5.6/my.cnf

    如果是老的版本,使用#屏蔽skip-networking,如下。

    1. #skip-networking

    如果是新的版本,使用#屏蔽bind-address。

    1. #bind-address = 127.0.0.1

    或者指定允许访问的ip

    1. #bind-address = 192.168.1.2

    然后重启mysql。

    1. /usr/local/mysql-5.6/support-files/mysql.server restart

    这里是用文件的方式来启动mysql,你可以用服务的方式。

    叶子在屏蔽#skip-networking后,再远程连接mysql就OK了。

    附录iptables防火墙的命令

    查询防火墙状态:

    1. [root@localhost ~]# service iptables status

    停止防火墙:

    1. [root@localhost ~]# service iptables stop

    启动防火墙:

    1. [root@localhost ~]# service iptables start

    重启防火墙:

    1. [root@localhost ~]# service iptables restart

    永久关闭防火墙:

    1. [root@localhost ~]# chkconfig iptables off

    永久关闭后启用:

    1. [root@localhost ~]# chkconfig iptables on

    编辑防火墙规则

    1. vi /etc/sysconfig/iptables

    重启防火墙的其他方式

    1. /etc/init.d/iptables restart

    结束

    你学会了吗?

  • 相关阅读:
    REDUCING THE SEARCH SPACE FOR HYPERPARAMETER OPTIMIZATION USING GROUP SPARSITY阅读笔记
    缓存穿透、缓存击穿、缓存雪崩区别和解决方案
    Jenkins中构建时提示:Couldn't find any revision to build. Verify the repository and branch config
    Docker中使用Dockerfile定制化jar启动时:at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264)
    Docker中部署mysql后SpringBoot连接时提示表不存在(修改表名忽略大小写)
    js使用y-seal实现印章功能
    手写js原生方法总结(简版)
    P5666
    CF653G
    P4649
  • 原文地址:https://www.cnblogs.com/chinway/p/MySQL.html
Copyright © 2011-2022 走看看