Back to blog
Mei 14, 20255 min read
DevOps

How to Install MySQL on Ubuntu Server

How to Install MySQL on Ubuntu Server

How to Install MySQL on an Ubuntu Server

Introduction

MySQL is a popular open-source relational database management system (RDBMS) widely used in web development. This guide will walk you through the process of installing MySQL on an Ubuntu server.

Prerequisites

  • An Ubuntu server with sudo privileges.
  • A stable internet connection.

Step 1: Update Your System

Before installing MySQL, make sure your system is up to date:

sudo apt update && sudo apt upgrade -y

Step 2: Install MySQL

Use the following command to install MySQL on your Ubuntu server:

sudo apt install mysql-server -y

Step 3: Secure MySQL Installation

After installation, run the security script to secure MySQL:

sudo mysql_secure_installation

This script will help you:

  • Set a root password.
  • Remove anonymous users.
  • Disallow root login remotely.
  • Remove test databases.

Step 4: Verify MySQL Installation

Ensure MySQL is running properly:

sudo systemctl status mysql

You should see a message indicating that MySQL is active and running.

Step 5: Log In to MySQL

To log in to your MySQL server, use:

sudo mysql -u root -p

Step 6: Basic MySQL Configuration

  • Change the root user’s authentication method:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your-password';
FLUSH PRIVILEGES;

  • Create a new database and user (optional):

CREATE DATABASE example_db;
CREATE USER 'example_user'@'localhost' IDENTIFIED BY 'user-password';
GRANT ALL PRIVILEGES ON example_db.* TO 'example_user'@'localhost';
FLUSH PRIVILEGES;

Conclusion

You have successfully installed MySQL on your Ubuntu server. Make sure to regularly update and secure your MySQL installation. Feel free to explore further MySQL configurations to suit your project needs.

© 2026 Dimas Eka Putra. All rights reserved.
Built with hope by Dimas Eka Putra