日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

liunx mysql端口没开_linuxmysql可以terminal登录,3306端口未打开原因记录(转)

發布時間:2025/3/15 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 liunx mysql端口没开_linuxmysql可以terminal登录,3306端口未打开原因记录(转) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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 betweenJavaand 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 ifmysqld 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

總結

以上是生活随笔為你收集整理的liunx mysql端口没开_linuxmysql可以terminal登录,3306端口未打开原因记录(转)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。