Home MySQL How to Install the Latest MySQL 8 in Ubuntu

How to Install the Latest MySQL 8 in Ubuntu

MySQL is a relational database system owned by Oracle Corporation and it has been a part of the Ubuntu repositories right from its earlier versions. The release cycles of Ubuntu and MySQL do not exactly match; hence in some older Ubuntu versions, the latest MySQL version will not be available in the repository.

Today, we will see how to install and configure the latest MySQL 8 on Ubuntu.

Installing MySQL 8 on Ubuntu

MySQL 8 is available in the official Ubuntu repositories starting from Ubuntu 20.04. If you are using Ubuntu 20.04 or higher, install MySQL 8 with the following command:

$ sudo apt install mysql-server

This will install all packages; including MySQL Client, MySQL Server, and all other required packages.

Install MySQL in Ubuntu
Install MySQL in Ubuntu

If you are using an Ubuntu version lower than 20.04, you need to first run the following command to download the MySQL apt repository deb file:

$ sudo wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.17-1_all.deb

Now, install the downloaded deb file using the following command. It will ask for the input of packages to be made available for install. Mark on ‘MySQL Server and Cluster’ and press the right arrow key to move the cursor on ‘Ok’, and hit Enter.

$ sudo dpkg -i mysql-apt-config_0.8.17-1_all.deb
Install MySQL APT Repository in Ubuntu
Install MySQL APT Repository in Ubuntu
Choose MySQL Server and Cluster
Choose MySQL Server and Cluster

Then choose the MySQL version from the next popup and mark on MySQL 8 and hit Enter.

Choose MySQL Server Version to Install
Choose MySQL Server Version to Install

You will once again be directed to the earlier screen. Choose ‘Ok’ from the list, and hit Enter.

Confirm MySQL Server and Cluster
Confirm MySQL Server and Cluster

Next, install MySQL 8 by simply running the following command, which will install MySQL Server, Client as well as other dependent packages.

$ sudo apt update
$ sudo apt install mysql-server
Install MySQL Server on Ubuntu
Install MySQL Server on Ubuntu

During MySQL Server installation, it will ask you to set a root password.

Set MySQL Root Password
Set MySQL Root Password

Next, set the default MySQL authentication method.

Set MySQL Authentication Method
Set MySQL Authentication Method

Finally, verify if MySQL has been installed by connecting to MySQL as the root user. Make sure to enter the root password that you have set during the installation.

$ sudo mysql -u root -p

In the MySQL prompt, run the following query to confirm if the MySQL server is working:

mysql> show databases;
Verify MySQL Installation
Verify MySQL Installation

Thus, MySQL has been installed and properly working.

Securing MySQL Server in Ubuntu

The installation of MySQL also installs a security script, which configures the MySQL installation for maximum security against the most common concerns.

$ sudo mysql_secure_installation

It will prompt for options like removal of anonymous users, remote login, etc. Enter the appropriate inputs: eg. password strength level, etc. Enter ‘y’ to configure the corresponding options.

Secure MySQL Server Installation
Secure MySQL Server Installation

The MySQL installation is now complete and the database is ready to use!

If you want to uninstall MySQL Server, you can read our guide – Completely Uninstall MySQL Server in Ubuntu

Conclusion

In this article, we have seen how to install MySQL 8 in Ubuntu. Let us know your thoughts and questions in the comments below.

Ravi Saive
I am an Experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

2 thoughts on “How to Install the Latest MySQL 8 in Ubuntu”

  1. In the 2nd step below:

    $ wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.16-1_all.deb
    

    I had to use:

    $ sudo wget -c https://dev.mysql.com/get/mysql-apt-config_0.8.16-1_all.deb
    

    to have write permissions for the file. Was installing on Linux Mint 20.x. Hope that helps someone.

    Reply

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.