Menu

How to Install MySQL 8 on Ubuntu 18.04

Install MySQL 8.0 on Ubuntu 18.04 for legacy systems. Standard support ended in June 2023; the MySQL APT repository offers only the 8.0 series for Bionic.

Posted on By
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 18.04 server from the MySQL APT repository.

Support status: Ubuntu 18.04 standard security maintenance ended in June 2023; Ubuntu Pro ESM is listed through April 2028. The MySQL APT repository currently publishes only MySQL 8.0 for Bionic. For a new server, see our MySQL 9.7 LTS guide for Ubuntu 26.04. Confirm the OS coverage in Ubuntu’s release list and the MySQL APT repository index.

Prerequisites

Before you install MySQL, you need to have the following prerequisites:

  • Ubuntu 18.04 server with a non-root user with sudo privileges
  • An internet connection

Step 1 - Update Package Repository

First, update your Ubuntu package repository to latest with:

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 Installation

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 18.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.