← Volver al blog

How to Install MySQL/MariaDB on Ubuntu

  • Xernode
  • 1 min de lectura
  • 4 de abril de 2026
Database mysql ubuntu installation mariadb database

Introduction

MySQL and MariaDB are popular open-source database servers used in many web applications. This guide shows you how to install and secure MySQL or MariaDB on Ubuntu.

Step-by-step Guide

  1. Update your package list
    • sudo apt update
  2. Install MySQL Server
    • sudo apt install mysql-servern
      • Or, to install MariaDB instead:
    • sudo apt install mariadb-server
  3. Start and enable the database service
    • For MySQL:n
      • sudo systemctl start mysql
      • sudo systemctl enable mysql
    • For MariaDB:n
      • sudo systemctl start mariadb
      • sudo systemctl enable mariadb
  4. Run the security script
    • sudo mysql_secure_installationn
      • Follow the prompts to set a root password, remove test databases, and secure your installation.
  5. Log in to the database server
    • sudo mysql -u root -pn
      • Enter your root password when prompted.
  6. (Optional) Create a new database and user
    • CREATE DATABASE mydatabase;
    • CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
    • GRANT ALL PRIVILEGES ON mydatabase.* TO 'myuser'@'localhost';
    • FLUSH PRIVILEGES;
    • EXIT;

Recommendations

  • Always set a strong root password.
  • Regularly back up your databases.
  • Keep your MySQL/MariaDB server updated for security.

Call To Action

eed a reliable VPS for your databases? Check out our hosting plans! https://xernode.com/#pricing

Related Guides