Find the answer to your Linux question:
Results 1 to 6 of 6
I'm pretty sure this was a bug with xampp installing mysql not correctly, see post below. I've been on working a program for java that uses mysql. It runs fine ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Sep 2009
    Posts
    11

    [SOLVED] MySQL & Java


    I'm pretty sure this was a bug with xampp installing mysql not correctly, see post below.

    I've been on working a program for java that uses mysql. It runs fine in windows but when I brought it over to my linux vps it keeps on giving me this:
    Code:
    04:28:33 [INFO] 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.
    04:28:33 [SEVERE] 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.
    04:28:33 [SEVERE]       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    04:28:33 [SEVERE]       at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    04:28:33 [SEVERE]       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    04:28:33 [SEVERE]       at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
    04:28:33 [SEVERE]       at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
    04:28:33 [SEVERE]       at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1116)
    04:28:33 [SEVERE]       at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:346)
    04:28:33 [SEVERE]       at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2334)
    04:28:33 [SEVERE]       at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2371)
    04:28:33 [SEVERE]       at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2163)
    04:28:33 [SEVERE]       at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:794)
    04:28:33 [SEVERE]       at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    04:28:33 [SEVERE]       at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    04:28:33 [SEVERE]       at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    04:28:33 [SEVERE]       at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    04:28:33 [SEVERE]       at java.lang.reflect.Constructor.newInstance(Constructor.java:532)
    04:28:33 [SEVERE]       at com.mysql.jdbc.Util.handleNewInstance(Util.java:407)
    04:28:33 [SEVERE]       at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:378)
    04:28:33 [SEVERE]       at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:305)
    04:28:33 [SEVERE]       at java.sql.DriverManager.getConnection(DriverManager.java:620)
    04:28:33 [SEVERE]       at java.sql.DriverManager.getConnection(DriverManager.java:222)
    04:28:33 [SEVERE]       at com.brodi.RevivedGaming.RevivedGamingMySQL.Connect(RevivedGamingMySQL.java:17)
    04:28:33 [SEVERE]       at com.brodi.RevivedGaming.RevivedGaming.onEnable(RevivedGaming.java:105)
    04:28:33 [SEVERE]       at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:118)
    04:28:33 [SEVERE]       at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:414)
    04:28:33 [SEVERE]       at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:187)
    04:28:33 [SEVERE]       at org.bukkit.craftbukkit.CraftServer.loadPlugin(CraftServer.java:83)
    04:28:33 [SEVERE]       at org.bukkit.craftbukkit.CraftServer.loadPlugins(CraftServer.java:61)
    04:28:33 [SEVERE]       at net.minecraft.server.MinecraftServer.e(MinecraftServer.java:204)
    04:28:33 [SEVERE]       at net.minecraft.server.MinecraftServer.a(MinecraftServer.java:191)
    04:28:33 [SEVERE]       at net.minecraft.server.MinecraftServer.d(MinecraftServer.java:131)
    04:28:33 [SEVERE]       at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:246)
    04:28:33 [SEVERE]       at net.minecraft.server.ThreadServerApplication.run(SourceFile:366)
    04:28:33 [SEVERE] Caused by: java.net.ConnectException: Connection refused
    04:28:33 [SEVERE]       at java.net.PlainSocketImpl.socketConnect(Native Method)
    04:28:33 [SEVERE]       at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:310)
    04:28:33 [SEVERE]       at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:176)
    04:28:33 [SEVERE]       at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:163)
    04:28:33 [SEVERE]       at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:384)
    04:28:33 [SEVERE]       at java.net.Socket.connect(Socket.java:546)
    04:28:33 [SEVERE]       at java.net.Socket.connect(Socket.java:495)
    04:28:33 [SEVERE]       at java.net.Socket.<init>(Socket.java:392)
    04:28:33 [SEVERE]       at java.net.Socket.<init>(Socket.java:235)
    04:28:33 [SEVERE]       at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.java:254)
    04:28:33 [SEVERE]       at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:295)
    04:28:33 [SEVERE]       ... 26 more
    MySQL is perfectly accessible from the phpMyAdmin. The MySQL command worked too after I create a symbolic link to the mysql socket for it. I think it is either the jdbc not being able to find the socket, or lampp installed it wrong somehow. The only reason I believe lampp installed it wrong is because I had to create the symbolic link to the correct socket.

    I've tried modifying my.cnf, but with no luck
    my.cnf
    Code:
    [mysqld]
    enable-socket
    
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    user=mysql
    bind-address=*REMOVED*
    socket=/var/run/mysql/mysqld.sock
    pid-file=/var/run/mysql/mysqld.pid
    basedir=/usr
    datadir/var/lib/mysql
    tmpdir=/tmp
    language=/usr/share/mysql/english
    # Default to using old password format for compatibility with mysql 3.x
    # clients (those using the mysqlclient10 compatibility package).
    old_passwords=1
    
    # Disabling symbolic-links is recommended to prevent assorted security risks;
    # to do so, uncomment this line:
    # symbolic-links=0
    
    [mysqld_safe]
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    Last edited by brodi816; 03-20-2011 at 03:58 AM.

  2. #2
    Just Joined!
    Join Date
    Jun 2006
    Posts
    6
    Well, I would try to use one of the IDEs (Eclipse or NetBeans or JDeveloper). They all make it easy.
    Did you install the Java connector for mySQL? It will not work without this. It needs to go into the jre/lib/ext directory

  3. #3
    Just Joined!
    Join Date
    Dec 2007
    Posts
    3
    Some things to check

    1. Can you log into MySQL from the Command Line? e.g. mysql -u root -p

    2. Are MySQL and your Java server on the same VPS? If so, unless you have lots of experience securing a Linux system, binding to a public IP address rather than the loopback address introduces lots of risks.

    3. Is iptables allowing the connection? Since you are not running on the loopback interface, your iptables rules may be blocking. Check the iptables rules for any likely problems, e.g. iptables -L -v

    4. There are some useful diagnostics steps at the MySQL web site. Google "Can't connect to MySQL server"

    BTW suggest obfuscating any IP addresses in future posts

  4. #4
    Just Joined!
    Join Date
    Dec 2009
    Location
    California
    Posts
    98
    The key is this: Connection refused

    Check your code - perhaps you were using "localhost" or 127.0.0.1 on the windows box and you didn't change it?
    Either that or the port number in your code is wrong. It should be 3306.

  5. #5
    Just Joined!
    Join Date
    Dec 2007
    Posts
    3
    And point made by jarome is an important one. Have you installed the mysql-java connector?

    For example, on a Fedora system it is called mysql-connector-java, e.g.
    yum install mysql-connector-java

    Probably has a similar name on a Debian/Ubuntu system.

    Once installed, the mysql-connector-java-5.1.15.jar [or whatever version number you have installed] needs to be copied to the relevant directory.

    For example on a Fedora Tomcat 6 system, default directory is following [replace MYWEBAPP with name of your specific web app] >

    /var/lib/tomcat6/webapps/MYWEBAPP/WEB-INF/lib/

  6. #6
    Just Joined!
    Join Date
    Sep 2009
    Posts
    11
    I did fix this problem by reformatting my vps and installed apche mysql and proftpd separately instead of using xampp/lampp. I could login into the mysql from command line, and mysql and java were on the same vps. I don't know what iptables are so i don't think that was the problem. I searched for about 6 hours yesterday all over google for solutions. I did have the mysql connector installed to /usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64/jre/lib/ext.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •