---
title: "How to install MariaDB or MySQL on an Ubuntu VPS | StreetHosting"
description: "Install and secure a MariaDB or MySQL database on an Ubuntu VPS: package, initial hardening, database and user creation, and safe remote access for your app."
url: "https://streethosting.com.br/en/guides/vps/install-mariadb-mysql-ubuntu-vps"
type: "page"
language: "en-US"
---

VPS · 3 min · Intermediate

Published on Jun 17, 2026 · Updated on Jun 17, 2026

# Install MariaDB or MySQL on an Ubuntu VPS

Almost every application needs a database. See how to install MariaDB or MySQL, run the security script, create a database and user, and allow access without exposing the server.

By [Equipe StreetHosting](https://streethosting.com.br/en/autores#equipe-streethosting) · StreetHosting infrastructure and support team

[Databases](https://streethosting.com.br/en/guides/topics/databases) [Security and hardening](https://streethosting.com.br/en/guides/topics/security) [Linux administration](https://streethosting.com.br/en/guides/topics/linux)

Summarize with:

[](https://chat.openai.com/?q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-mariadb-mysql-ubuntu-vps.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "ChatGPT") [](https://claude.ai/new?q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-mariadb-mysql-ubuntu-vps.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Claude") [](https://www.google.com/search?udm=50&aep=11&q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-mariadb-mysql-ubuntu-vps.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Google AI Mode") [](https://x.com/i/grok?text=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-mariadb-mysql-ubuntu-vps.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Grok") [](https://www.perplexity.ai/search/new?q=Summarize%20the%20key%20points%20of%20this%20StreetHosting%20guide%3A%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-mariadb-mysql-ubuntu-vps.%20Highlight%20the%20step-by-step%20instructions%2C%20the%20prerequisites%20and%20the%20most%20common%20mistakes. "Perplexity")

Share:

[](https://x.com/intent/tweet?text=How%20to%20install%20MariaDB%20or%20MySQL%20on%20an%20Ubuntu%20VPS&url=https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-mariadb-mysql-ubuntu-vps "Share on X") [](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-mariadb-mysql-ubuntu-vps "Share on Facebook") [](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-mariadb-mysql-ubuntu-vps "Share on LinkedIn") [](https://wa.me/?text=How%20to%20install%20MariaDB%20or%20MySQL%20on%20an%20Ubuntu%20VPS%20https%3A%2F%2Fstreethosting.com.br%2Fen%2Fguides%2Fvps%2Finstall-mariadb-mysql-ubuntu-vps "Share on WhatsApp")

For agents: Copy as Markdown [.md](https://streethosting.com.br/en/guides/vps/install-mariadb-mysql-ubuntu-vps.md)

In this guide 5 sections

* [MariaDB or MySQL](https://streethosting.com.br/en/guides/vps/install-mariadb-mysql-ubuntu-vps#mariadb-ou-mysql)
* [Install the database](https://streethosting.com.br/en/guides/vps/install-mariadb-mysql-ubuntu-vps#instalar)
* [Initial security](https://streethosting.com.br/en/guides/vps/install-mariadb-mysql-ubuntu-vps#seguranca-inicial)
* [Database and user](https://streethosting.com.br/en/guides/vps/install-mariadb-mysql-ubuntu-vps#banco-e-usuario)
* [Remote access](https://streethosting.com.br/en/guides/vps/install-mariadb-mysql-ubuntu-vps#acesso-remoto)

Quick answer

To install a database on an **Ubuntu VPS**, install the **MariaDB** or **MySQL** package, run the security script to close what ships open, create a database and a dedicated user with minimal permissions and, if the application is on another machine, allow access only from its IP. Never expose the database to the whole internet.

## MariaDB or MySQL[](https://streethosting.com.br/en/guides/vps/install-mariadb-mysql-ubuntu-vps#mariadb-ou-mysql)

MariaDB and MySQL share the same origin and are compatible in most cases. If your application does not require one of them, the choice barely matters. What matters is installing securely and sizing the database for the load, which weighs on CPU and disk just like any [API hosted on a VPS](https://streethosting.com.br/en/guides/vps/host-nodejs-on-vps).

## Install the database[](https://streethosting.com.br/en/guides/vps/install-mariadb-mysql-ubuntu-vps#instalar)

1. Update the system packages.
2. Install the MariaDB or MySQL package.
3. Confirm the service is active and enabled at boot.

## Initial security[](https://streethosting.com.br/en/guides/vps/install-mariadb-mysql-ubuntu-vps#seguranca-inicial)

A freshly installed database ships with open settings. Do not skip the security script. Without it, anonymous accounts and remote root stay available to anyone who can reach the port.

Run the script, set a strong password for the admin, remove anonymous users and disable remote root access. This simple step already shuts out a good part of automated attacks.

## Database and user[](https://streethosting.com.br/en/guides/vps/install-mariadb-mysql-ubuntu-vps#banco-e-usuario)

Create a database for your application and a dedicated user with permission only on that database. This principle of least privilege means that if the application is compromised, the damage stays contained in that database and does not reach the whole server.

* Strong password for the database admin
* One dedicated user per application
* Permission restricted to the matching database
* Automatic database backups configured

## Remote access[](https://streethosting.com.br/en/guides/vps/install-mariadb-mysql-ubuntu-vps#acesso-remoto)

If the application runs on another machine, allow access only from its IP using the [UFW firewall](https://streethosting.com.br/en/guides/vps/ufw-firewall-ubuntu-vps) and reinforce it with [Fail2ban](https://streethosting.com.br/en/guides/vps/fail2ban-ssh-vps-setup). For databases that grow and need more I/O, a [Ryzen VPS](https://streethosting.com.br/en/vps/ryzen) with NVMe delivers fast response times.

Database backups are not optional. Schedule regular dumps and actually test the restore, because a backup that has never been restored is not a reliable backup.

In this guide

* [MariaDB or MySQL](https://streethosting.com.br/en/guides/vps/install-mariadb-mysql-ubuntu-vps#mariadb-ou-mysql)
* [Install the database](https://streethosting.com.br/en/guides/vps/install-mariadb-mysql-ubuntu-vps#instalar)
* [Initial security](https://streethosting.com.br/en/guides/vps/install-mariadb-mysql-ubuntu-vps#seguranca-inicial)
* [Database and user](https://streethosting.com.br/en/guides/vps/install-mariadb-mysql-ubuntu-vps#banco-e-usuario)
* [Remote access](https://streethosting.com.br/en/guides/vps/install-mariadb-mysql-ubuntu-vps#acesso-remoto)

## Frequently asked questions

Are MariaDB and MySQL the same?

They are very close. MariaDB started as a fork of MySQL and stays largely compatible. For most applications, the choice makes no difference. Check whether your software specifically recommends one of them.

Do I need to run the security script?

Yes. Right after installation, the database ships with open settings. The script sets the admin password, removes anonymous accounts and closes remote root access, which is essential.

Should I open the database to the internet?

No. Expose the database only to the IP of the application that needs it, through the firewall. Databases open to the internet are a constant target for attacks and leaks.

Can I run the application and the database on the same VPS?

Yes, and it is common on small projects. In that case, the application reaches the database locally, with no port exposed on the network. As you grow, splitting the database from the application improves performance and security.

Next step

See VPS plans

Root VPS in Brazil with NVMe and Anti-DDoS.

[See VPS plans](https://streethosting.com.br/en/vps)

[See Ryzen VPS Ryzen 9 9950X VPS in São Paulo with root access, NVMe and gamer Anti-DDoS.](https://streethosting.com.br/en/vps/ryzen) [See Xeon VPS Xeon VPS for steady workloads, automation and long-running projects.](https://streethosting.com.br/en/vps/xeon)

## Related guides

[VPS Intermediate How to set up Fail2Ban on a VPS: SSH, Nginx and repeat offenders Fail2Ban reads your logs, spots the IPs that fail too often and bans them in the firewall. Learn how to set it up on Ubuntu 24.04, where the package defaults change how jails behave, and how to manage bans day to day. 8 min Read guide](https://streethosting.com.br/en/guides/vps/fail2ban-ssh-vps-setup) [VPS Beginner UFW on Ubuntu VPS: firewall rules without losing SSH UFW makes the Ubuntu firewall simpler, but one rule in the wrong order locks you out of your VPS. Learn how to enable it without losing SSH, open only what you need, deal with Docker, and get back in through the console if something goes wrong. 10 min Read guide](https://streethosting.com.br/en/guides/vps/ufw-firewall-ubuntu-vps) [VPS Intermediate How to host a Node.js app on a VPS in Brazil A Node.js app in production needs a process manager, a reverse proxy, HTTPS and automatic restarts. Follow the complete walkthrough on an Ubuntu VPS in São Paulo, close to your users and to Brazilian integrations. 9 min Read guide](https://streethosting.com.br/en/guides/vps/host-nodejs-on-vps)

[← Back to the Guide Center](https://streethosting.com.br/en/guides)
