You can log on to linuxmysql using terminal. the reason for Port 3306 being disabled is recorded as _ MySQL

Source: Internet
Author: User
You can use terminal to log on to linuxmysql. the reason for Port 3306 being disabled is bitsCN.com.

Linux suse11 can log on to terminal to perform various operations normally. jdbc web program running on tomcat has an exception:

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 supported Ed any packets from the server.

Cause search

Normally, you can connect to msql suse and run the following command:

1. run the command netstat-talnp to verify whether Port 3306 is enabled:

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 check whether the mysql service is running

Test :~ # Ps aux | grep mysql
Root 4254 0.0 0.0 2940 1332? S/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/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. sock -- ports = 3306
Root 8002 0.0 0.0 2264 680 pts/2 S + grep mysql

3. check the process lsof-I: 3306 running on port 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)

Run the above command on the problematic machine

1. netstat-talnp cannot see the tcp connection bound to Port 3306

2. ps aux | grep mysql display service is running

3. check whether mysql is running on port 3306 in lsof-I: 3306. The result does not show that mysql is not running on port 3306.

Conclusion: Although the mysql service is running, it can be operated through teminal, but it is not running on port 3306, so it cannot be connected through the jdbc connection.

Then, check the network information. the skip-networking parameter in the mysql configuration is not commented. the parameter skip-networking is used to stop listening on the TCP/IP port, all interactions with mysqld must be performed through Unix sockets or named pipelines.

The configuration file is annotated as follows:

# 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!

Comment out the parameter skip-networking and restart the mysql service. The jdbc program can connect to mysql normally.

The network encounters the same exception. other possible causes:

1.

The tomcat program connects to the mysql database of the server and reports

Com. mysql. jdbc. exceptions. jdbc4.CommunicationsException: Communications link failure
The last packet sent successfully to the server was 0 milliseconds ago. The driverhas not supported Ed any packets from the server.
An error occurs. later, I used a java program to directly connect to the database. the same error occurs. the database connection and user name and password are all correct.
I have checked many situations on the Internet, and it is useless to set database user permissions or database connection wait time (wait_timeout.
The connection to the local database is okay. the local database version is 5.0.37, the server database version is 5.0.19, and the JDBC driver version is:
Mysql-connector-java-5.1.9-bin.jar.
This problem plagued a day, later think about changing the 5.0 driver 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: 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.

Refer:

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

 BitsCN.com

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.