Cannot connect to mysql/mariadb from java

July 23, 2014 2.2k views

Hi - I am having significant difficulties in connecting my (locally run in eclipse) java application to mysql hosted on the Digital Ocean platform.

Strangely enough however, using mysql workbench I can connect with no issues at all from my desktop.

For slightly more comprehensive report with images i have posted on stack overflow here - - unfortunately some power hungry idiot decided to mark my question solved / duplicated when the solution he provided also does not work.

Please can someone with experience of writing java applications that run on the Digital Ocean platform please let me know how to approach solving this issue.

Kind regards


1 comment
  • Hi Ricki!

    Thanks for posting your question. Since a lot of our site is responsive and users can reply from all sorts of devices, we recommend keeping as much information on the DO site as possible, to facilitate answers.

    Just as an FYI, adding pictures to DO questions can be done in markdown with

    ![alt text](Image URL)

    See exhibit A below.

    very cute cat

    I look forward to seeing your question answered :)

1 Answer

I think that the comment on your StackOverflow question is closing in on the problem. When you connect to the database through MySql Workbench, it is being tunneled via SSH (on port 22) and then connects to MySql on localhost port 3306. Sure enough, running nmap on your IP address shows that port 3306 is not open.

Are you running some kind of firewall? You need to open port 3306.

  • Hi Andrew,

    I just ran nmapfrom my local machine and you were right - port 3306 was indeed closed. I opened the port and then ran the following to allow remote connections to the DB:

    GRANT ALL ON *.* to username@'%' IDENTIFIED BY 'password'; 
    GRANT ALL ON *.* to username@localhost IDENTIFIED BY 'password'; 
    flush privileges;

    That appears to have done the trick.

    Thank you for your help!

Have another answer? Share your knowledge.