LCWD LogoLearn Code With DurgeshLCWD
HomeCoursesTutorialsBlogsContact
About LCWDAbout Durgesh Tiwari
Flex Box Hero
LearnCodeWithDurgesh Logo

Learn Code With Durgesh

Offering free & premium coding courses to lakhs of students via YouTube and our platform.

Explore

  • About Us
  • Courses
  • Blog
  • Contact
  • FlexBox Game

Legal

  • Privacy Policy
  • Terms & Conditions
  • Refund Policy
  • Support

Contact

  • 📞 +91-9839466732
  • [email protected]
  • Substring Technologies, 633/D/P256 B R Dubey Enclave Dhanwa Deva Road Matiyari Chinhat, Lucknow, UP, INDIA 226028
© 2025 Made with ❤️ by Substring Technologies. All rights reserved.
Deploying Spring Boot with Mysql on DigitalOcean droplet

Deploying Spring Boot with Mysql on DigitalOcean droplet

By durgeshkumar8896 • Thu Sep 22 2022

Deploying Spring Boot with Mysql on DigitalOcean droplet

Digital Ocean logo

1. Login to Digital Ocean account

2. Create a project

3. Create a new droplet

Create a new key pair and add to the droplet key section.

When droplet creation finishes then reset the password for root. It is mandatory.

4. Login using the console . I prefer to login using ssh.

                

 ssh -i  [filekey] root@ipaddress

        5.     Before doing anything run update command:

sudo apt update

 

 


Installing MySQL

1. After update command run command below

sudo apt install mysql-server               

   Press Y if prompted and it will install mysql on the machine

2. Start the mysql server by running the command

sudo systemctl start mysql.service 

3. Check the status all fine or not.             

sudo systemctl status mysql.service

This is show Active(running) status

 

4. Now it's time to configure mysql

5. Alter the root user password  first

sudo mysql

ALTER USER ‘root’@’localhost’ IDENTIFIED WITH mysql_native_passowrd BY ‘password’



6.  Type exit.

7.    Now Login with root user      

sudo mysql -u root -p 

8.  Now run mysql secure script

sudo mysql_secure_installation   

Provide the answer of prompted questions

9. Creating a dedicated user so that we can access this user outside the machine also.

mysql -u root -p

CREATE USER 'username'@'host' IDENTIFIED BY 'password';

GRANT ALL PRIVILEGES ON *.* TO ‘user’@'host’;

FLUSH PRIVILEGES;

exit

 

10. Restart the mysql server so that changes reflect.

sudo systemctl restart mysql.service

11. Finally done with mysql installation and now we can use mysql.


Let's Connect mysql to our local workbench

1. First , convert public key to pem

ssh-keygen -p -m PEM -f [yourpublickey]

Type this command to convert , make sure to  backup the key first.

2. Open the workbench and add a new connection.

3.  For Connection Name, enter any name you’d like that helps you identify the connection you’re making later. 

4. Change the Connection Method to Standard TCP/IP over SSH.

5. For SSH Hostname, enter your droplet IP address. If your server accepts SSH connections on a different port, enter the IP address, followed by a colon and port number.

6. For SSH Username(root), enter the username you use to log into the server via SSH.

7. For SSH Password, enter the password you use for your SSH user. If you use public keys instead of passwords, select an SSH key for authentication.

8. For MySQL Hostname and MySQL Server Port, use the default values.

HostName: 127.0.0.1
Port: 3306

9. For Username, enter the MySQL username.

10. For Passwords, you can either enter the password or leave it blank. If you do not store the MySQL password in MySQL Workbench, a prompt will request the password each time you attempt to connect to the database.

11. Choose Test Connection to ensure your settings are correct.

12. Choose OK to create the connection.

Create your database using mysql work now.


Lets install Java and Deploy Spring boot

1.On you droplet console type command:

sudo apt install openjdk-11-jre-headless

sudo apt install openjdk-11-jdk-headless

I am installing java 11 

Important: Using above command java 11 get installed but javac is not.

There is no need to install javac because we are going to just run application not compile or build but if you want you can install

2. Build your spring boot application with prod profile and server config details in your properties files.

3. Upload this jar to droplet machine folder using FileZilla in our case we created new folder with projects

4. Now Create two script with following commands.

start.sh

#!/bin/bash

nohup java -jar /projects/blog-app-apis-0.0.1-SNAPSHOT.jar --spring.profiles.active=prod > /projects/log.txt 2>&1 &

echo $! > /projects/pid.file

stop.sh

kill $(cat /projects/pid.file)

Important : Change your folders path and filename accordingly.

5. Run start script 

sudo ./start.sh

Congratulation project is now running on you given port in project config file.

You can now test it on 

http://ip-adress:portnumber

 

Share this article ...

💬WhatsApp📘Facebook💼LinkedIn🐦X

Trending Blogs...

AI: Boon or Curse? Advantages & Disadvantages Explained

AI: Boon or Curse? Advantages & Disadvantages Explained

Artificial Intelligence (AI) is no longer just a concept of the future—it is already shaping our present. From asking Alexa or Siri to play music, using Google Maps for directions, or experiencing personalized recommendations on Netflix, AI has become a part of our everyday life.

The Future of Technology: Quantum Computing and Its Ecosystem

The Future of Technology: Quantum Computing and Its Ecosystem

Quantum computing isn’t just another buzzword—it’s a completely new way of thinking about computers. Unlike our everyday laptops or phones that run on classical computing, quantum computers use the strange but powerful rules of quantum mechanics.

Tailwind CSS Cheat Sheet – Complete Utility Class Guide 2025

Tailwind CSS Cheat Sheet – Complete Utility Class Guide 2025

Tailwind CSS Cheat Sheet – Complete Utility Class Guide 2025

Expert-Level JavaScript Interview Q&A for 2025: Crack Advanced JS Interviews

Expert-Level JavaScript Interview Q&A for 2025: Crack Advanced JS Interviews

Get ready for tough coding interviews with this collection of advanced JavaScript interview questions and answers. Designed for experienced developers who want to master complex JS concepts and impress recruiters.

Ace Your Coding Interview: JavaScript Q&A for Intermediate Learners

Ace Your Coding Interview: JavaScript Q&A for Intermediate Learners

Prepare for your next coding interview with this collection of JavaScript interview questions and answers for intermediate developers. Strengthen your JS concepts and boost your confidence.

Most Asked JavaScript Interview Questions with Answers

Most Asked JavaScript Interview Questions with Answers

Q1. What is JavaScript? JavaScript is a programming language mainly used to make web pages interactive and dynamic. It runs in the browser, and with Node.js, it can also run on the server.

Share this article ...

💬WhatsApp📘Facebook💼LinkedIn🐦X