You are here:

Installing MySQL on Ubuntu 21.04 / 20.04

Introduction

This guide will detail the process of MySQL installation on Ubuntu 21.04 and Ubuntu 20.04. MySQL employs a relational database and Structured Query Language (SQL) for data management. As an open-source database management system, it is frequently utilized in the widely adopted LAMP (Linux, Apache, MySQL, PHP/Python/Perl) stack.

Prerequisites

To proceed with this guide, ensure you have the following:

  • An Ubuntu 20.04 server with either a non-root user or access to a root user account.

Short Version

The condensed procedure for installation is direct. Begin by updating the package manager, then proceed to install MySQL and initiate the configuration. Execute the provided commands.

sudo apt-get update -y
sudo apt-get install mysql-server -y
mysql_secure_installation

Detailed Version

Step 1 - Installing MySQL

Initially, update the package manager to acquire the latest available packages. Utilize the following command.

sudo apt-get update -y

Now we can install MySQL. Use the following command:

sudo apt-get install mysql-server -y

Step 2 - Configuring MySQL

For a new MySQL installation, it is advisable to execute the security script that accompanies it. This script will prompt you with a series of security-related questions. Respond according to your preferences. To run the script, use the following command:

mysql_secure_installation

Step 3 - Testing MySQL

Upon installation, MySQL should have initiated automatically. Confirm this by using the following command to check.

systemctl status mysql.service

You will observe output resembling this.

* mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:>
Active: active (running) since Fri 2022-04-01 15:47:58 CEST; 18min ago
Process: 3494 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=e>
Main PID: 3502 (mysqld)
Status: "Server is operational"
Tasks: 37 (limit: 2217)
Memory: 352.7M
CGroup: /system.slice/mysql.service
|___3502 /usr/sbin/mysqld

Apr 01 15:47:57 ubuntu-115 systemd[1]: Starting MySQL Community Server...
Apr 01 15:47:58 ubuntu-115 systemd[1]: Started MySQL Community Server.

This output shows that MySQL is up and running

Was this article helpful?
Dislike 0