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;
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 ' 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.server' (10061)
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的区别的更多相关文章
- 安装好mysql后允许远程连接
安装好mysql后允许远程连接 http://blog.sina.com.cn/s/blog_3eba8f1c0100tsox.html http://blog.csdn.net/zxyvb/arti ...
- MongoDB win安装后无法远程连接访问
mongoDB安装后无法远程连接访问,原因是端口没有开放允许连接的权限 开启允许连接的权限: 管理工具-高级win防火墙
- mysql 发现 navicat 可以远程连接,代码无法远程连接
navicat可以远程连接, root账号也可以用代码连接. 其他的用户无法远程连接. 原因: 1.先检查下 mysql数据库里面 的 servers 表是否存在. 2.更新或者创建用户之后 使用: ...
- [修]开启MySQL远程访问权限 允许远程连接
原文地址:http://www.cnblogs.com/XL-Liang/archive/2012/05/03/2481310.html 这个地址也许更有帮助:http://www.cppblog.c ...
- 开启MySQL远程访问权限 允许远程连接
1.登陆mysql数据库 mysql -u root -p 查看user表 mysql> use mysql;Database changedmysql> select host,user ...
- linux网络连接的查看和端口的监听
网络软件都是由客户端和服务端组成,由服务端在服务器上监听指定的端口处理接收到的数据,而客户端是向服务器端监听的端口发送数据,并由服务器端对该数据进行处理,然后将处理结果返回给客户端. 那么我们在lin ...
- centos 安装mysql密码修改后还是不能连接的原因
centos 上安装mysql密码修改后还是不能连接出现错误:ERROR 1142 (42000): SELECT command denied to user ''@'localhost' for ...
- linux 下解决mysql root 权限无法远程连接问题
问题描述:MySQL数据库安装成功后,在服务器本地可以连接成功,但是使用工具navicat无法进行远程连接,如图: 原因:MySQL默认只允许root帐户在本地登录,如果要在其它机器上连接mysql, ...
- centos7通过yum安装mysql,并授权远程连接
安装: CentOS 7的yum源中没有正常安装MySQL的mysql-sever文件,需要去官网上下载(通过安装mysql的yum容器,再通过yum安装mysql) 注:安装前,需要卸载所有的mar ...
随机推荐
- 直通BAT面试算法精讲课2
对于一个int数组,请编写一个冒泡排序算法,对数组元素排序. 给定一个int数组A及数组的大小n,请返回排序后的数组. 测试样例: [1,2,3,5,2,3],6 [1,2,2,3,3,5] clas ...
- jq的each理解
1种 通过each遍历li 可以获得所有li的内容 <!-- 1种 --> <ul class="one"> <li>11a</li> ...
- STM32串口发送第一个字符丢失解决之道
stm32用printf函数重定向到串口USART1发现第一个字符没打印出来具体如下: 刚开始修改fputc函数如下: int fputc(int ch,FILE *f){USART_SendData ...
- python读书笔记-《A Byte of Python》中文第三版后半部分
编辑器:windows,linux 不要用notepad,缩进糟糕 -------------- 5.18缩进 同一层次的语句必须有相同的缩进.每一组这样的语句称为一个块. i = 5 2 prin ...
- WPF 分辨率无关性原理
WPF在计算窗口尺寸大小时使用的是系统的DPI设置.WPF窗口以及窗口中所有的元素都是使用设备无关单位度量.一个设备无关单位被定义为1/96英寸. [物理单位尺寸]=[设备无关单位尺寸]*[系统DPI ...
- AngularJS学习——价格计算器
利用AngularJs实现价格计算器,总价满100免运费.(熟悉$watch的使用)
- svn update解决冲突
(p) postpone 暂时推后处理,我可能要和那个和我冲突的家伙商量一番 (df) diff-full 把所有的修改列出来,比比看 (e) edit 直接编辑冲突的文件 (mc) mine-con ...
- UVA 11040 Add bricks in the wall
https://vjudge.net/problem/UVA-11040 找规律 #include<cstdio> using namespace std; ][]; int main() ...
- 51Nod 1094 和为k的连续区间 | 水
Input示例 6 10 1 2 3 4 5 6 Output示例 1 4 #include "cstdio" #include "algorithm" #in ...
- 2015/8/9 到家了,学完了CodeCademy的Python
昨天坐了20多个小时的硬座回家.发现在网络信号差的火车上也是学习的好地方.如果你的手机电量不足的话,带上两本书简直是绝配.我在火车上阅读了两百多页的内容,并没有多大的疲累,那样无聊的环境里面能看书学习 ...