1

I am attempting to setup a MySQL 5.6 database to work with my application. While working with it however, I cannot seem to get any sort of connection happening. This is the error message I am getting...

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.
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1137)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:356)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2504)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2541)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2323)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:832)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:408)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:417)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:344)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at ServerDatabase.<init>(ServerDatabase.java:25)
at Server.main(Server.java:60)

Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.connect(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at java.net.Socket.<init>(Unknown Source)
at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:258)
at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:306)
... 16 more

I have looked up this problem extensively, however I cannot find a solution that fixes my specific problem. The closest I found was this however I followed the steps and got no result. Here is a code snippet to help diagnose...

public ServerDatabase() {
    Connection conn = null;
    Statement stmt = null;

    try {
        Class.forName("com.mysql.jdbc.Driver");
        conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/dbname", "dev", "**********");

I also have the MySQL information for that user account...

+------------------------------------------------------------------------------------------------------------------------------+
| Grants for dev@%                                                |
+-------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'dev'@'%' IDENTIFIED BY PASSWORD '*C52E324F3EA43A030DCB940689107C77F44391E4' WITH GRANT OPTION |
+-------------------------------------------------------------------------------------------------------------------------------+

Some other quick asides to hopefully narrow down responses...

  1. I have totally disabled my Windows Firewall, and do not run any other firewall for my local network.
  2. the bind-address on my.cnf was not set originally, I set it to 0.0.0.0 with no result so I removed it from the setup.

[mysqld]

# The next three options are mutually exclusive to SERVER_PORT below.
# skip-networking
# enable-named-pipe
# The Pipe the MySQL Server will use
# socket=mysql

# The TCP/IP Port the MySQL Server will listen on
port=9118

#bind-address = 127.0.0.1

3. I am able to connect using the MySQL command line prompt no problem, and setup the database already.
Community
  • 1
  • 1
Sh4d0wsPlyr
  • 948
  • 12
  • 28
  • I assume that "dbname" is the actual name of your DB? – ltalhouarne Jul 16 '14 at 02:55
  • Yes, I just changed it for this. – Sh4d0wsPlyr Jul 16 '14 at 03:00
  • as you have used `dev` as the username make sure u have created a user by the name dev and specified password from root account and granted priviledges to it – SparkOn Jul 16 '14 at 04:56
  • As the grant message has shown, I have already created the user account and granted it proper privileges. I don't think this is the issue, as the error given in my post indicates that no connection was established. – Sh4d0wsPlyr Jul 16 '14 at 11:44

2 Answers2

0

Modify your bind-address in my.cnf

"#bind-address = 127.0.0.1"

restart mysql

sudo /etc/init.d/mysql restart
ltalhouarne
  • 4,586
  • 2
  • 22
  • 31
0

I found a solution that works for me, and likely will work for anyone else who is interested or experiencing problems outside the programming aspect. I would like to clarify, this is the easy way out and may not meet everyones needs. I am a Java Developer, and I can issue SQL commands fairly proficiently. I am not however, a server administrator or anything of the sort. For me this works perfectly.

Step 1. Download WAMP server. http://www.wampserver.com/en/#download-wrapper

Step 2. Install + Setup. Follow the instructions on their website for more details.

Step 3. Set the server to online by right clicking the WAMP icon. After that you can log into it using the MySQL console provided (the password/username at the time of posting was root // password). The defaults may have changed.

After doing that, I was able to instantly connect to the MySQL database using JDBC.

Sh4d0wsPlyr
  • 948
  • 12
  • 28