• mysql部署后无法远程连接的原因(错误代码10061),服务监听127.0.0.1和0.0.0.0的区别


      在Ubuntu上部署mysql服务并添加了一个非root用户后,发现无法远程连接,

    Navicat连接mysql出现2003——can't connect to mysql server on localhost(10061)。

    在网上搜索了一圈后,几乎都指向一个解决方案:修改配置文件/etc/mysql/my.cnf中的一项配置:

    bind-address          = 127.0.0.1

    改为:

    bind-address            = 0.0.0.0

    虽然大家都这么说,但是没有说明原因,于是我又找了一番,终于找到了,特转载于此,

    原文在这里,感谢原作者。

    ========== 以下为转载 ==========

    服务监听在127.0.0.1和0.0.0.0上,到底有什么区别呢?给个实际的例子,大家看看

    今天发现在nb1380的mysql从nb1381连不上?  

    1、使用grant加权限,失败

    mysql> select user,host,password from mysql.user;
    11 rows in set (0.00 sec)
    mysql> grant all privileges on *.* to 'root'@'nb1381' identified by '  ' with grant option;

    2、telnet失败,考虑可能是iptables限制,加规则,无效

    root@nb1380:/var/log/mysql# iptables -I INPUT -p tcp --dport 3306 -j ACCEPT

    3、猜测可能是监听在127.0.0.1上,而不是0.0.0.0上,查看my.cnf,果然是这个原因   

    root@nb1380:/var/log/mysql# vim /etc/mysql/my.cnf 
    bind-address            = 127.0.0.1 改为:
    bind-address            = 0.0.0.0

     重启mysql,果然telnet通了

    root@nb1381:~# telnet nb1380 3306
    Trying 192.168.64.43...
    Connected to nb1380.
    Escape character is '^]'.

     mysql也能连接了

    root@nb1381:~# mysql -uroot -p -hnb1380
    Enter password: 
    Welcome to the MySQL monitor.  Commands end with ; or g.
    Your MySQL connection id is 40
    Server version: 5.6.33-0ubuntu0.14.04.1 (Ubuntu)
    Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
    Oracle is a registered trademark of Oracle Corporation and/or its
    affiliates. Other names may be trademarks of their respective
    owners.
    Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
    mysql>

    总结:

    3306端口监听在127.0.0.1,只有本机客户端可以访问,其他服务器无法访问

    3306端口如果监听在0.0.0.0上,如果没有端口限制,那么其他服务器则可以连接该服务器的该端口

     ========== 转载结束 ==========

      文章到这里还没结束,通过错误代码10061,我查到了官方文档的说法。连接如下:

    https://dev.mysql.com/doc/refman/8.0/en/can-not-connect-to-server.html

    这里剪辑部分内容:

    The error (2003) Can't connect to MySQL server on 'server' (10061) indicates that the network connection has been refused. You should check that there is a MySQL server running, that it has network connections enabled, and that the network port you specified is the one configured on the server.

    Make sure that the server has not been configured to ignore network connections or (if you are attempting to connect remotely) that it has not been configured to listen only locally on its network interfaces. If the server was started with --skip-networking, it will not accept TCP/IP connections at all. If the server was started with --bind-address=127.0.0.1, it will listen for TCP/IP connections only locally on the loopback interface and will not accept remote connections.

    其实官方文档已经写清楚了,以后有问题,找官方文档结合别人的实践经验效率更高。

  • 相关阅读:
    省、市、地区三级联动
    window.open(url); 传递参数,中文乱码问题
    TortoiseSVN打分支、合并分支、切换分支
    用SoupUI导出webservice 客户端代码遇到的问题:由于 accessExternalSchema 属性设置的限制而不允许 'file' 访问, 因此无法读取方案文档 'xjc.xsd'。
    oracle 创建定时任务
    分布式服务框架原理与实践_李林锋著_笔记
    idea部署到tomcat不打印log
    idea登录github报错 Can't login: Connection reset
    idea部署web工程到tomcat_无法访问此网站问题排查
    使用myeclipse tomcat插件部署web项目时报错 an internal error occurred during add deployment . java.lang.nullpointerexception
  • 原文地址:https://www.cnblogs.com/tlz888/p/9570523.html
Copyright © 2020-2023  润新知