Complete Guide: Installing Databases on Ubuntu Server
Learn how to install and configure MongoDB, PostgreSQL, and MySQL on your Ubuntu server for your web development projects.
Want to be a web developer and Technical geek? Welcome, to ThapaTechnical. Home of web developer and creativity. We make articles on Technology, Social cause, University Important topics and also u will get all videos source code and Notes for Free of ThapaTechnical YouTube channel.
Learn how to install and configure MongoDB, PostgreSQL, and MySQL on your Ubuntu server for your web development projects.
Click here to Buy India's Best Hosting 👉 www.hostg.xyz/SHGZy
For Thapa Family 💥 Use the discount code THAPA7 to get Extra 10% OFF!
👉 Watch Complete VPS Setup: Watch Tutorial
🌐 Link to VPS Security Setup Before Hosting: Security Guide
MongoDB is a NoSQL database that stores data in flexible, JSON-like documents. Let's go through the installation process on Ubuntu.
Search on Google "mongodb community edition install", and click the first link.
On the MongoDB website, choose Install on Linux option.
Choose your Linux distribution, which for us is Ubuntu.
Go directly to the "Install MongoDB Community Edition" section and copy-paste the commands into your terminal.
We are using Ubuntu 24, so we'll follow the instructions for that version.
You can check your Ubuntu version using:
After installation, enable and start the MongoDB service:
Mongosh is installed by default, so you can test your installation:
Now, MongoDB is installed locally in your VPS. To use it in your projects, use the following connection string:
PostgreSQL is a powerful, open-source object-relational database system. Let's set it up on Ubuntu.
Search on Google "PostgreSQL Install" and click on the first link.
Select your Linux distribution (Ubuntu in our case).
Ubuntu includes PostgreSQL by default in its package lists, so the installation is straightforward.
PostgreSQL can only be used by the postgres user initially. Let's switch to that user:
psql
is a CLI tool to interact with PostgreSQL. You can run PostgreSQL queries and commands from here.
Create a database user matching your Linux username:
For ease of use, let's make the new user a superuser:
Create a database with the same name as your user:
Exit out of PSQL and the postgres user, then test with your Linux user:
Now you can connect to PostgreSQL from your projects using:
PostgreSQL by default runs on port 5432.
Example: postgresql://thapa:1234@localhost:5432/mydatabase
MySQL is one of the most popular relational database management systems. Let's install it on Ubuntu.
Before installing any packages, refresh your package lists:
Install MySQL server using apt:
It's recommended to run the security script after installing MySQL:
Verify that MySQL is running:
Create a new database user for your projects:
To see all the users of MySQL:
Create a new user:
Grant full privileges to the new user:
Breakdown of the GRANT command:
1. Privileges
SELECT, INSERT, UPDATE, DELETE
ALL means all privileges
Example: GRANT SELECT, INSERT ON my_database.* TO thapa;
2. ON database.table
*.* means to allow the user permission to all databases and all tables inside them
Example: GRANT SELECT, INSERT ON my_database.* TO thapa;
This allows the user access to all tables of my_database
3. TO 'user'@'host'
As we are connected to a local database, we can just use user_name
4. WITH GRANT OPTION (Optional)
This allows the user to pass their granted privileges to others
Flush privileges to apply changes:
Exit MySQL using the exit
command.
Open MySQL CLI using your newly created user:
-u flag specifies the username to login with
-p flag prompts for the password
Now you have your MySQL connection string:
Example: mysql://thapa:thapa%401234@localhost:3306/database
3306 is the default MySQL port