Learn Code With Durgesh LogoLCWD
HomeCoursesBlogsContact Us
HomeCoursesBlogsContact Us
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

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 durgesh • 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...

Maven Tutorial

Maven Tutorial

Maven is a build automation tool primarily used for Java projects. It addresses two main aspects of building software: dependency management and project build lifecycle management.

Important DSA Topics for placements

Important DSA Topics for placements

Data Structures and Algorithms (DSA) are fundamental building blocks of computer science. A strong understanding of DSA is essential for every developer, regardless of their specialization.

Amazing Windows key shortcuts in Windows 11

Amazing Windows key shortcuts in Windows 11

Shortcuts are everyone’s favorite, be it in life or in Keyboard. We don’t know about life but we have some amazing shortcut tricks for your keyboard, which are newly introduced in windows 11. Let's have a look and understand these amazing shortcuts to reduce our finger pain

Share this article ...

💬WhatsApp📘Facebook💼LinkedIn🐦X