By xzx7moodxzx
Hi, I need to connect to mySQL from java I don’t know what’s code I need to write*_* it’s different between localHost database and ssh database. Can I connect to my database from java application ?
This textbox defaults to using Markdown to format your answer.
You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!
The most secure way to connect to a remote MySQL server is to set up an SSH tunnel. This will use a secure SSH session to bind port 3306 on your Droplet to whatever port you want on your local machine, and forward all traffic through the secure tunnel. This will allow you to connect to MySQL without enabling true remote access, as the traffic is going through the SSH tunnel so MySQL considers it local traffic.
Take a look at this tutorial, specifically Example 1:
You will need to replace port 110 with 3306 but the rest should be the same. Once you have the tunnel set up, you can connect to your database using Java the same way you would if the server were hosted on your local machine. If you already have a MySQL server installed locally, you might want to use a different port than 3306 on the local end.
Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.
Full documentation for every DigitalOcean product.
The Wave has everything you need to know about building a business, from raising funding to marketing your product.
Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.
New accounts only. By submitting your email you agree to our Privacy Policy
Scale up as you grow — whether you're running one virtual machine or ten thousand.
Sign up and get $200 in credit for your first 60 days with DigitalOcean.*
*This promotional offer applies to new accounts only.