LInux MySQL 端口验证
linux suse11在terminal可以正常登录进行各种操作,在tomcat运行jdbc web程序异常:
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
原因查找
正常可以连接msql suse 运行以下命令情况如下:
1. 运行命令netstat -talnp验证3306端口是否打开:
test:~ # netstat -talnp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN 4620/mysqld
。。。。。。
2.运行命令 ps aux|grep mysql看mysql服务是否在运行
test:~ # ps aux|grep mysql
root 4254 0.0 0.0 2940 1332 ? S 06:05 0:00 /bin/sh /usr/local/mysql/bin/mysqld_safe --datadir=/usr/local/mysql/data --pid-file=/usr/local/mysql/data/test.pid
mysql 4620 0.1 0.9 301476 37428 ? Sl 06:05 0:13 /usr/local/mysql/bin/mysqld --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data --plugin-dir=/usr/local/mysql/lib/plugin --user=mysql --log-error=/usr/local/mysql/data/test.err --pid-file=/usr/local/mysql/data/test.pid --socket=/usr/local/mysql/mysql.sock --port=3306
root 8002 0.0 0.0 2264 680 pts/2 S+ 09:21 0:00 grep mysql
3.查看3306端口运行的进程 lsof -i :3306
test:~ # lsof -i :3306
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mysqld 4620 mysql 12u IPv4 10559 0t0 TCP *:mysql (LISTEN)
问题机器运行上面运行命令
1.netstat -talnp 看不到绑定到3306端口的tcp连接
2.ps aux|grep mysql 显示服务在运行
3. lsof -i :3306查看mysql是否运行在3306端口,未有显示mysql服务没有运行在3306端口
结论:mysql服务虽然在运行,可以通过teminal操作,但没有运行在3306端口,所以通过jdbc连接连接不上。
后查看网络资料mysql配置中skip-networking未注释,参数skip-networking起的作用是:mysql不再在TCP / IP端口上进行监听,与mysqld的所有互动都必须通过Unix套接字或命名管道进行。
配置文件注释如下
# Don't listen on a TCP/IP port at all. This can be a security enhancement,
# if all processes that need to connect to mysqld run on the same host.
# All interaction with mysqld must be made via Unix sockets or named pipes.
# Note that using this option without enabling named pipes on Windows
# (via the "enable-named-pipe" option) will render mysqld useless!
将参数skip-networking注释重启mysql服务,jdbc程序连接mysql正常。
网络遇见同样异常,可能的其它原因:
1.
tomcat程序连接服务器mysql数据库,报
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driverhas not received any packets from the server.
错误,后来用java程序直接连接数据库,还是一样的错误,数据库连接,用户名密码都没有问题。
在网上查了很多情况,什么数据库用户权限设置,还是数据库连接等待时间(wait_timeout)设置,都没用。
而连接本地的数据库就没问题,本地数据库版本:5.0.37,服务器数据库版本:5.0.19,JDBC驱动版本:
mysql-connector-java-5.1.9-bin.jar。
这个问题困扰了一天,后来想想换换5.0的驱动看看怎么样,结果在网上找了个mysql-connector-java-5.1.14-bin.jar的驱动,结果OK了。
2.
CommunicationsException: Communications link failure
If you get a SQLException: Connection refused or Connection timed out or a MySQL specific CommunicationsException: Communications link failure, then it means that the DB isn't reachable at all. This can have one or more of the following causes:
IP address or hostname in JDBC URL is wrong.
Hostname in JDBC URL is not recognized by local DNS server.
Port number is missing or wrong in JDBC URL.
DB server is down.
DB server doesn't accept TCP/IP connections.
DB server has run out of connections.
Something in between Java and DB is blocking connections, e.g. a firewall or proxy.
To solve the one or the other, follow the following advices:
Verify and test them with ping.
Refresh DNS or use IP address in JDBC URL instead.
Verify it based on my.cnf of MySQL DB.
Start the DB.
Verify if mysqld is started without the --skip-networking option.
Restart the DB and fix your code accordingly that it closes connections in finally.
Disable firewall and/or configure firewall/proxy to allow/forward the port.
参考:
http://stackoverflow.com/questions/2983248/com-mysql-jdbc-exceptions-jdbc4-communicationsexception-communications-link-fai
http://blog.csdn.net/gucapg/article/details/17509969
http://4925054.blog.51cto.com/4915054/1154263
LInux MySQL 端口验证的更多相关文章
- Linux下Mysql端口修改及防火墙开端口
用户权限问题:https://blog.csdn.net/weixin_43670802/article/details/103019598 Linux下修改Mysql默认的3306端口 如下: 1. ...
- linux开关端口问题
linux开关端口问题: 我们知道一些常用的端口,比如mysql的端口为3306,sql的端口为:1433,以及tomcat的端口为 8008等等一样! 当这些端口在linux下是没有开启时,我们是无 ...
- Linux Mysql数据库安全配置
Linux Mysql数据库安全配置 目录: 1.修改mysql管理员账号root的密码(2种方法) 2.修改mysql管理员账号root 3.mysql管理员root账号密码遗忘解决办法(2种方法 ...
- Linux通过端口转发来访问内网服务(端口转发访问阿里云Redis数据库等服务)
# 安装rinetd wget http://www.boutell.com/rinetd/http/rinetd.tar.gz&&tar -xvf rinetd.tar.gz& ...
- linux 常用端口【转载】
原文地址: http://blog.csdn.net/u013943420/article/details/65938696 一个计算机最多有65535个端口,端口不能重复.这65536个端口被分为两 ...
- Linux MySQL 常见无法启动或启动异常的解决方案
Linux MySQL 常见无法启动或启动异常的解决方案 在 Linux 上自建 MySQL 服务器,经常遇到各种无法启动或启动后异常的问题,本文列举一些常见问题的解决办法. 注意:以下错误日志提示, ...
- linux暴露端口可以被外部访问
linux暴露端口可以被外部访问,把端口号换成要暴露的端口:/sbin/iptables -I INPUT -p tcp --dport 3306 -j ACCEPT Centos 7 开启端口Cen ...
- mysql端口查看与修改-netstat命令使用
linux上使用netstat察看mysql端口和连接 linux上使用netstat察看mysql端口和连接 近日发现写的一个java程序的数据库连接在大压力下工作不打正常,因此研究了一下dbcp, ...
- linux mysql远程连接
今天在本地连接linux服务端的mysql始终报错61,谷歌后找到原因: linux的mysql默认是不允许远程连接操作的,在stack上面找到方法:修改mysql配置文件/usr/local/mys ...
随机推荐
- java提升路线书单(原文自知乎刘欣)
复制黏贴自知乎刘欣大神,作为个人的书单与指导路线 原文链接:https://www.zhihu.com/question/19848946/answer/92536822 刘欣 追寻内心的真正兴趣 ...
- 《UML大战需求分析》阅读随笔(一)
UML:Unified Modeling Language(统一建模语言) 作为我专业学科里的一门语言,其目的就是交流,同客户交流,同自己交流. 用图像和文字,详细地讲解将要做的工程的 需求和功能细节 ...
- c# 如何中List<object>中去掉object对象中的重复列数据?
//去掉重复 var title = modelList.GroupBy(m => m.Title.ToLower().Trim()).Select(m => new { ID = m.F ...
- iis下搭建通过phpstudy集成的环境,phpmyadmin导入数据库无法应解决办法
本人非常喜欢phpstudy的集成php+mysql环境,一键搞定,但是不知道为什么搭建的phpmyadmin的数据库管理器,无法上传,点击无反应 发现上传数据的界面有点不同 正常情况下是这样的: 非 ...
- 【第二课】WEBIX 入门自学-获取WEBIX及相关资料
下载WEBIX组件库 http://webix.com/download/ WEBIX在线文档 http://docs.webix.com/ 离线的手册 下载
- 2-Sat问题
二分+2-Sat 判断是否可行 输出字典序最小的解 输出字典序可行解 其实这些都是小问题,最重要的是建图,请看论文. 特殊的建边方式,如果a b是一对,a必须选,那么就是b->a建边. HDU ...
- linux 目录权限的特殊之处
目录的读权限,不能进入目录.仅允许我们读目录,获得在该目录中所有文件名的列表,但无法查看目录中文件的内容. 目录的执行权限,可以进入目录,但不允许我们读取目录的文件列表,但可以查看目录中文件的内容.当 ...
- sort命令
1.默认情况下,sort命令,以字母序进行文本排序sort word.txt2.如果想对数字进行排序,可以使用-n参数sort num.txt -n3指定列排序下面是对passwd文件,以冒号(:)进 ...
- Storm 中什么是-acker,acker工作流程介绍
概述 我们知道storm一个很重要的特性是它能够保证你发出的每条消息都会被完整处理, 完整处理的意思是指: 一个tuple被完全处理的意思是: 这个tuple以及由这个tuple所导致的所有的tupl ...
- hdu 2037简单贪心--活动安排问题
活动安排问题就是要在所给的活动集合中选出最大的相容活动子集合,是可以用贪心算法有效求解的很好例子.该问题要求高效地安排一系列争用某一公共资源的活动.贪心算法提供了一个简单.漂亮的方法使得尽可能多的活动 ...