在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;
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  -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
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
Server version: 5.6.-0ubuntu0.14.04. (Ubuntu)
Copyright (c) , , 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.

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

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

  1. 安装好mysql后允许远程连接

    安装好mysql后允许远程连接 http://blog.sina.com.cn/s/blog_3eba8f1c0100tsox.html http://blog.csdn.net/zxyvb/arti ...

  2. MongoDB win安装后无法远程连接访问

    mongoDB安装后无法远程连接访问,原因是端口没有开放允许连接的权限 开启允许连接的权限: 管理工具-高级win防火墙

  3. mysql 发现 navicat 可以远程连接,代码无法远程连接

    navicat可以远程连接, root账号也可以用代码连接. 其他的用户无法远程连接. 原因: 1.先检查下 mysql数据库里面 的 servers 表是否存在. 2.更新或者创建用户之后 使用:  ...

  4. [修]开启MySQL远程访问权限 允许远程连接

    原文地址:http://www.cnblogs.com/XL-Liang/archive/2012/05/03/2481310.html 这个地址也许更有帮助:http://www.cppblog.c ...

  5. 开启MySQL远程访问权限 允许远程连接

    1.登陆mysql数据库 mysql -u root -p 查看user表 mysql> use mysql;Database changedmysql> select host,user ...

  6. linux网络连接的查看和端口的监听

    网络软件都是由客户端和服务端组成,由服务端在服务器上监听指定的端口处理接收到的数据,而客户端是向服务器端监听的端口发送数据,并由服务器端对该数据进行处理,然后将处理结果返回给客户端. 那么我们在lin ...

  7. centos 安装mysql密码修改后还是不能连接的原因

    centos 上安装mysql密码修改后还是不能连接出现错误:ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for ...

  8. linux 下解决mysql root 权限无法远程连接问题

    问题描述:MySQL数据库安装成功后,在服务器本地可以连接成功,但是使用工具navicat无法进行远程连接,如图: 原因:MySQL默认只允许root帐户在本地登录,如果要在其它机器上连接mysql, ...

  9. centos7通过yum安装mysql,并授权远程连接

    安装: CentOS 7的yum源中没有正常安装MySQL的mysql-sever文件,需要去官网上下载(通过安装mysql的yum容器,再通过yum安装mysql) 注:安装前,需要卸载所有的mar ...

随机推荐

  1. ywy_c_asm题

    未知出处 题意: 定义一个无穷长的数列,满足以下性质:$1.X_{2n}=-{X_{n}}$ $2.X_{2n}=(-1)^{(n+1)}*X_{n}$ $3.X_{2n-1}=(-1)^{(n+1) ...

  2. 四连测Day3

    题目链接:https://pan.baidu.com/s/1_vsHfMI_qO-9IDxmFLkHfg 密码: uza8 T1: 小奥的一笔画,判连通性,查奇偶点即可 #include<ios ...

  3. GoLand安装配置

    目录 下载 安装 破解 运行 参考网址 GoLand配置 下载 1 下载路径:https://pan.baidu.com/s/1JJ-Oxx9NkEK-PrwcvLys7Q,提取码:o0e5 2 下载 ...

  4. [zhuan]VMware中bridge方式网络不能上网的解决办法

    http://jingpin.jikexueyuan.com/article/31601.html 安装好VMware 7后,打开原来的虚拟机文件,发现不能上网,原来的Ethernet是设置的Brid ...

  5. 在Linux中新增与删除用户可以使用命令:Useradd

    在Linux中新增与删除用户可以使用命令:Useradd 我们先使用man命令理解一下Useradd的用法 新增与删除用户操作需要先获取高级用户权限 输入命令:sudo -i 确定后输入高级用户密码 ...

  6. Spring Boot 打包部署

    一.打包成jar并部署 1.工程--右键选择运行配置: 在Goals中输入: org.apache.maven.plugins:maven-jar-plugin:.RELEASE:repackage ...

  7. 数据结构&图论:欧拉游览树

    ETT可以称为欧拉游览树,它是一种和欧拉序有关的动态树(LCT是解决动态树问题的一种方案,这是另一种) dfs序和欧拉序是把树问题转化到区间问题上然后再用数据结构去维护的利器 通过借助这两种形式能够完 ...

  8. 【BZOJ1038】【ZJOI2008】瞭望塔 [模拟退火]

    瞭望塔 Time Limit: 10 Sec  Memory Limit: 162 MB[Submit][Status][Discuss] Description 致力于建设全国示范和谐小村庄的H村村 ...

  9. 【TYVJ】1520 树的直径

    [算法]树的直径 memset(a,0,sizeof(a)) #include<cstdio> #include<algorithm> #include<cstring& ...

  10. Vuejs - 强大的指令系统

    在 Vuejs 中,指令(Directives)是带有 v- 前缀的特殊属性.指令属性的预期值是 单个 Javascript 表达式(v-for 是个例外).指令的职责是,当表达式改变时,将其产生的连 ...