MySQL is a fully managed database service to deploy cloud-native applications using the world's most popular open source database based on Structured Query Language (SQL).
This tutorial will describe how to install MySQL database server on an Ubuntu 20.04.
To follow this tutorial, you will need:
Ubuntu 20.04 Server set up by following this initial server setup guide, including a sudo non-root user privileges.
Step 1 - Installing MySQL
At the time of writing this article, the latest version of MySQL available from the official Ubuntu 20.04 repositories is MySQL version 8.
To install MySQL on the Ubuntu server, we will follow the steps below:
First, update the apt package index:
sudo apt update
Then, install the MySQL Server package by typing the command:
sudo apt install mysql-server
After completing the installation, the MySQL service will start automatically. To check if the MySQL service is running, type the command below:
sudo systemctl status mysql
You’ll see output similar to the following:
● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2020-10-18 18:15:11 -03; 1min 14s ago Main PID: 3158 (mysqld) Status: "Server is operational" Tasks: 38 (limit: 2270) Memory: 329.7M CGroup: /system.slice/mysql.service └─3158 /usr/sbin/mysqld
Step 2 - Securing MySQL
The MySQL installation comes with a script called
mysql_secure_installation to run after installation and to configure some important security settings.
Run the security script by typing:
When executing this command, you will be asked if you would like to configure the ** Validate Password Plugin ** , which can be used to test the strength of your password in MySQL and improve the security. There are three levels of password validation policy, low, medium and strong. Press ENTER if you don’t want to use this plugin.
On the next question at the prompt, will be to set your password for the root user of MySQL. The script will also ask you to remove the anonymous user, restrict root user access to the localhost snd remove the test database. For these questions, you must answer Y
Step 3 - Check Installation
To finish the installation, we will check the status of the service.
sudo systemctl status mysql.service
You'll see output similar to the following:
● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled) Active: active (running) since Sun 2020-10-18 18:15:11 -03; 2min 39s ago Main PID: 3158 (mysqld) Status: "Server is operational" Tasks: 40 (limit: 2270) Memory: 330.2M CGroup: /system.slice/mysql.service └─3158 /usr/sbin/mysqld
If MySQL is not running, you can start it with the command below:
sudo systemctl start mysql
Let's confirm the version that was installed with the command:
sudo mysqladmin -p -u root version
You should see output similar to this:
mysqladmin Ver 8.0.21-0ubuntu0.20.04.4 for Linux on x86_64 ((Ubuntu)) Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners.
Server version 8.0.21-0ubuntu0.20.04.4 Protocol version 10 Connection Localhost via UNIX socket UNIX socket /var/run/mysqld/mysqld.sock Uptime: 4 min 2 sec
Threads: 2 Questions: 9 Slow queries: 0 Opens: 126 Flush tables: 3 Open tables: 47 Queries per second avg: 0.037
This means MySQL is up and running.
You now have a basic MySQL configuration installed on your server securely.