LInux MySQL Port Verification

Source: Internet
Author: User



Linux SUSE11 runs JDBC Web program exceptions in Tomcat when terminal can perform various operations in a normal logon:



Com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:Communications link Failure
The last packet sent successfully to the server was 0 milliseconds ago. The driver has no received any packets from the server.



Reason Lookup



Normal can connect mSQL SuSE run the following command as follows:



1. Run the command NETSTAT-TALNP Verify that Port 3306 is open:



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. Run the command PS aux|grep MySQL to see if the MySQL service is running



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. View the process running on port 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)



Problem machine run above Run command



1.NETSTAT-TALNP cannot see TCP connections bound to Port 3306



2.ps aux|grep MySQL display service is running



3. Lsof-i: 3306 Check if MySQL is running on Port 3306, no show MySQL service is not running on port 3306



Conclusion: Although the MySQL service is running, it can be operated via teminal, but it is not running on port 3306, so the JDBC connection is not connected.



After viewing the network data MySQL configuration skip-networking not commented, the role of the parameter skip-networking is: MySQL no longer listens on the TCP/IP port, all interactions with mysqld must be done through UNIX sockets or named pipes.



The configuration file comments are as follows



# Don ' t listen on a TCP/IP port at all. This can is a security enhancement,
# If all processes this need to connect to mysqld run on the same host.
# All interaction with Mysqld must is made via Unix sockets or named pipes.
# Note that the using this option without enabling named Pipes on Windows
# (via the "enable-named-pipe" option) would render mysqld useless!



Restart the MySQL service with the parameter skip-networking comment, and the JDBC program connects to MySQL normally.



The network meets the same anomalies, possibly other reasons:



1.The Tomcat program connects to the server MySQL database, reported



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.
Error, later with the Java program directly connected to the database, or the same error, database connection, user name password is not a problem.
There are a lot of things on the Internet, what database user rights settings, or database connection wait time (wait_timeout) settings, are useless.
There is no problem connecting to the local database, local database version: 5.0.37, Server database version: 5.0.19,JDBC driver version:
Mysql-connector-java-5.1.9-bin.jar.
This problem troubled a day, and then think about changing the driver of the 5.0 to see how, the results on the Internet to find a Mysql-connector-java-5.1.14-bin.jar driver, the results are OK.



2.Communicationsexception:communications link Failure



If you get a sqlexception:connection refused or Connection timed out or a MySQL specific Communicationsexception:communi Cations link failure, then it means that the DB isn ' t reachable at all. This can has one or more of the following causes:



IP address or hostname in JDBC URL is wrong.
Hostname in JDBC URLs are not recognized by local DNS server.
Port number is the missing or wrong in JDBC URL.
DB server is down.
DB server doesn ' t accept TCP/IP connections.
DB server has a 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 the 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.



Reference:



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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.