This guide will show you how to install MySQL on Ubuntu 24.04 using official PPA. MySQL is a popular database used to store and manage data. Whether you’re setting up a website or an application, MySQL can help you keep your data organized and accessible. Follow these simple steps, and you’ll have MySQL up and running on your Ubuntu system in no time.

Step 1: Update Your System

First, update your system to make sure all your packages are up-to-date. Open a terminal and run the following command:


sudo apt update && sudo apt upgrade -y

This command will update the package list and install the latest versions of the packages.

Step 2: Add the MySQL APT Repository

To get the latest version of MySQL, add the MySQL APT repository from the official MySQL site. Visit the official download page to get latest version of package or use the following command to download the repository package.


wget https://dev.mysql.com/get/mysql-apt-config_0.8.30-1_all.deb

Once the download is complete, install the package:


sudo dpkg -i mysql-apt-config_0.8.30-1_all.deb

During the installation, you will be prompted to select the MySQL version. You can also set the root account password or keep it empty.

Step 3: Install MySQL

After adding the MySQL APT repository, update your package list again:


sudo apt update

Now, install MySQL by running this command:


sudo apt install mysql-server -y

This command will download and install MySQL on your system.

Step 4: Start MySQL Service

After installation, you need to start the MySQL service. Run this command to start the service:


sudo systemctl start mysql

To make sure MySQL starts automatically when your system boots, enable the service:


sudo systemctl enable mysql

Step 5: Secure MySQL Installation

MySQL comes with a security script to help secure your installation. Run the following command to start the security script:


sudo mysql_secure_installation

You will be asked a series of questions to secure your MySQL installation. Here are the recommended responses:

  • Set up the VALIDATE PASSWORD PLUGIN: Choose Y and select a level of password validation, or choose N if password is already set during installation or use Unix socket authentication
  • Set root password: Choose Y and enter a strong password for the root user.
  • Remove anonymous users: Choose Y.
  • Disallow root login remotely: Choose Y.
  • Remove test database: Choose Y.
  • Reload privilege tables: Choose Y.

Step 6: Verify MySQL Installation

To check if MySQL is installed and running correctly, log in to the MySQL root user account with this command:


sudo mysql -u root -p

Enter the root password you set earlier. If you see the MySQL prompt (mysql>), it means MySQL is installed and running correctly.

Step 7: Create a Database (Optional)

If you want to create a new database, you can do it from the MySQL prompt. For example, to create a database named testdb, run:


CREATE DATABASE testdb;

To see the list of databases, use:


SHOW DATABASES;

To exit the MySQL prompt, type:


EXIT;

Conclusion

You have successfully installed MySQL on Ubuntu 24.04. You can now start using MySQL to manage your databases. If you have any issues, you can refer to the MySQL documentation or seek help from online forums.

On production servers don’t forgot to configure regular database backup. You can use our readymade simple mysql backup script