How to Install MySQL 8 on Ubuntu 20.04
Install MySQL 8.0 on Ubuntu 20.04 for existing systems. Standard support ended in May 2025; Ubuntu Pro ESM is listed through April 2030.
On this page
MySQL 8 is a major MySQL series that includes features such as common table expressions, window functions, atomic DDL, and JSON functions.
In this tutorial, we will show you how to install MySQL 8 on an Ubuntu 20.04 server from the MySQL APT repository.
Support status: Ubuntu 20.04 standard security maintenance ended in May 2025; Ubuntu Pro ESM is listed through April 2030. The MySQL APT repository currently publishes only MySQL 8.0 for Focal. For a new server, see our MySQL 9.7 LTS guide for Ubuntu 26.04. Confirm coverage in Ubuntu’s release list and available MySQL series in the APT repository index.
Prerequisites
Before you install MySQL, you need to have the following prerequisites:
- Ubuntu 20.04 server with a non-root user with sudo privileges
- An internet connection
Step 1 - Update Package Repository
First, update your Ubuntu package repository:
sudo apt update
Step 2 - Add the MySQL APT Repository
Install the current MySQL APT repository configuration package. As of September 2026, the package is 0.8.40-1:
sudo apt install -y wget
wget https://dev.mysql.com/get/mysql-apt-config_0.8.40-1_all.deb
sudo dpkg -i mysql-apt-config_0.8.40-1_all.deb
In the configuration dialog, select MySQL Server & Cluster, then choose the mysql-8.0 series. Refresh APT’s package information:
sudo apt update
Step 3 - Install MySQL Server
Now install MySQL server:
sudo apt update
sudo apt install mysql-server
This will install MySQL 8.0.
Step 4 - Start MySQL Service
Once installed, the MySQL service will start automatically. You can check it with:
sudo systemctl status mysql
Step 5 - Secure MySQL
It’s recommended that you run the mysql_secure_installation script to improve MySQL security:
sudo mysql_secure_installation
This will set the root password, remove anonymous user accounts, disable root logins outside localhost, etc.
Step 6 - Create a Dedicated MySQL User
It’s best practice to create a dedicated MySQL user for your applications instead of using the root account:
sudo mysql
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypass';
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'localhost' WITH GRANT OPTION;
Replace “myuser” and “mypass” with your desired username and password.
Step 7 - Test MySQL
To test if MySQL is working properly, connect to the mysql server with the new user created:
mysql -u myuser -p
Enter the password when prompted. Then you’ll enter into the MySQL shell.
Run a simple command to test connectivity:
SHOW DATABASES;
This will show the available databases.
Step 8 - Create a Sample Database and Table
Let’s create a sample database and table to validate everything is working:
CREATE DATABASE mytestdb;
USE mytestdb;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50),
email VARCHAR(50)
);
You now have MySQL 8 installed and can start using it!
Conclusion
That’s it! We’ve shown you how to install the latest MySQL 8 on Ubuntu 20.04 from the official MySQL APT repository. You can now start developing applications using MySQL or connect it to your web apps.
If you want to learn more about MySQL, please use our MySQL tutorials and MySQL Reference.