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 ...
随机推荐
- 史上最全Linux提权后获取敏感信息方法
http://www.freebuf.com/articles/system/23993.html 在本文开始之前,我想指出我不是专家.据我所知,在这个庞大的区域,没有一个“神奇”的答案.分享,共享( ...
- BUG:Open quote is expected for attribute "{1}" associated with an element type "id".
BUG原因:Mybatis的xml文件中id缺少双引号: 正确的应该是:
- google 浏览器的调试模式
1.电脑模式: 而在手机模式下的调试是:
- Chrome控制台报错个人总结(不定时更新)
最近开始使用Chrome控制台检测代码错误,对于经常碰到的报错做一个汇总,免得每次遇到都要重新想一遍策略,错误原因,重复劳动,浪费时间. 由于不是每个错误都能碰到,以下仅列出个人写代码时经常碰到的报错 ...
- asyncio 实现 aiohttp
#asyncio 没有提供http协议的接口 aiohttp import asyncio import socket from urllib.parse import urlparse async ...
- concurrent.futures 使用及解析
from concurrent.futures import ThreadPoolExecutor, as_completed, wait, FIRST_COMPLETED from concurre ...
- MVP应用在android app上
使用MVP模式来解耦activity中业务代码和界面代码.在activity中,将其中的业务抽象到presenter层:将其中的界面代码抽象到View层. MVP模式: 一个软件被划分成三层,View ...
- 【BZOJ】1577: [Usaco2009 Feb]庙会捷运Fair Shuttle
[题意]公车从1开到n,有k群牛想从一个点到达另一个点,公车最多乘坐c个人,牛群可以拆散,问最多载多少牛到达目的地. [算法]贪心+堆 [题解]线段和点的贪心,一般有按左端点排序和按右端点排序两种方法 ...
- js获取屏幕高度宽度
获取各种屏幕的宽度和高度Javascript: 网页可见区域宽: document.body.clientWidth网页可见区域高: document.body.clientHeight网页可见区域宽 ...
- 【遍历集合】Java遍历List,Map,Vector,Set的几种方法
关于list,map,set的区别参考http://www.cnblogs.com/qlqwjy/p/7406573.html 1.遍历list @Test public void testList( ...