How to install MySQL 8.0 on Ubuntu 24.04

This article explains how to install MySQL 8.0 on Ubuntu 24.04, a popular open-source relational database management system. Options include using Ubuntu’s APT repositories or MySQL’s official repositories for the latest stable release. After installation, managing and securing MySQL 8.0 is crucial, and specific commands can be used for uninstallation.

This article explains how to install MySQL 8.0 on Ubuntu 24.04.

MySQL 8.0 is a popular open-source relational database management system. It stores and manages data for various web applications and software. Combining MySQL 8.0 with Ubuntu provides a stable and efficient database management and application development platform.

There are multiple ways to install the MySQL database server on Ubuntu 24.04. You can use the version available in Ubuntu’s default APT repositories or opt for the latest stable release directly from MySQL’s official APT repositories.

The steps below walk you through installing MySQL 8.0 on Ubuntu 24.04.

Install MySQL 8.0 via Ubuntu APT repositories

The easiest way to install MySQL is from the default Ubuntu APT repositories. However, the versions in those repositories may not necessarily be the latest.

First, update Ubuntu packages by running the command below.

sudo apt update
sudo apt upgrade

Then, run the command below to install it.

sudo apt install mysql-server

The command above will install MySQL 8.0 ( the current version as I’m writing this) on Ubuntu 24.04.

Install MySQL 8.0 with MySQL Community Server

Another way to install the latest and most stable version of MySQL 8.0 on Ubuntu is to add its official repositories and install it from there.

First, install some prerequisites by running the command below.

sudo apt install dirmngr ca-certificates software-properties-common apt-transport-https curl lsb-release

Then, run the command below to import its repository GPG key.

curl -fsSL http://repo.mysql.com/RPM-GPG-KEY-mysql-2023 | sudo gpg --dearmor | sudo tee /usr/share/keyrings/mysql.gpg > /dev/null

Next, run the command below to add the MySQL 8.0 repository to Ubuntu 24.04.

echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/mysql.gpg] http://repo.mysql.com/apt/ubuntu $(lsb_release -cs) mysql-8.0" | sudo tee -a /etc/apt/sources.list.d/mysql.list

Now that you have successfully added the MySQL 8.0 GPG key and its repositories run the command below to update Ubuntu and install the server.

sudo apt update
sudo apt install mysql-community-server

When prompted during the installation, type and confirm a root password. Leave it blank to enable passwordless login using UNIX socket based authentication.

Select to use a strong password encryption (Recommended) option when prompted.

Once installed, you can use the commands below to start, stop, enable, restart, or disable MySQL service.

sudo systemctl start mysql
sudo systemctl stop mysql
sudo systemctl enable mysql
sudo systemctl restart mysql
sudo systemctl disable mysql

Run MySQL security script

After installing the MySQL database on Ubuntu, it’s recommended to run its security script to enhance and perform some house cleaning.

sudo mysql_secure_installation

Follow the prompts until you’re done.

Uninstall MySQL 8.0

Finally, if you no longer want to use MySQL 8.0 and want to remove it, use the steps below.

sudo systemctl stop mysql --now
sudo apt autoremove mysql-community-server
sudo apt autoremove mysql-server
sudo rm /etc/apt/sources.list.d/mysql.list

That should do it!

Conclusion:

  • MySQL 8.0 is a robust and popular open-source relational database management system suitable for various web applications and software.
  • Installing MySQL 8.0 on Ubuntu 24.04 can be accomplished through the default APT repositories or by adding MySQL’s official repositories for the latest stable release.
  • After installation, managing MySQL 8.0 involves starting, stopping, enabling, restarting, or disabling the MySQL service using systemctl commands.
  • Running MySQL’s security script after installation is recommended to enhance security and perform necessary housekeeping.
  • If the need arises to uninstall MySQL 8.0, specific commands can be used to stop, remove, and clean up the installation.

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *