How to Install MySQL 8 on Ubuntu 22.04

You are currently viewing How to Install MySQL 8 on Ubuntu 22.04

MySQL is a popular open-source relational database management system (RDBMS). It is used by a wide variety of applications, including web applications, mobile applications, and desktop applications.

In this tutorial, you will learn how to install MySQL 8 on Ubuntu 22.04.

Prerequisites

Before you begin, you will need the following:

  • A computer running Ubuntu 22.04
  • A user account with sudo privileges

Step 1: Update the package index

The first step is to update the package index. This will ensure that you have the latest versions of the packages available.

Code snippet

sudo apt update

Step 2: Install MySQL

The next step is to install MySQL. You can do this with the following command:

Code snippet

sudo apt install mysql-server

This will install the MySQL server and all of the necessary components.

Start the MySQL server by running the command below

systemctl start mysql

After it’s started, then enable the MySQL server

systemctl enable mysql 

Step 3: Change the Root Password

Open a terminal and log in to the MySQL server as the ‘root’ user using the current password:

mysql -u root -p

The default password is empty. Then set up a new password by running this command.

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';

Step 4: Configure MySQL

Once MySQL is installed, you will need to configure it. You can do this with the following command:

Code snippet

sudo mysql_secure_installation

This will prompt you to set a password for the root user and remove some of the default accounts that are created when MySQL is installed.

MySQL will now be started and listening for connections.

Testing MySQL

You can test MySQL by connecting to it with the following command:

Code snippet

mysql -uroot -p

You will be prompted to enter the password that you set for the root user in Step 3. Once you have entered the password, you will be connected to the MySQL server.

You can now create databases, tables, and users. For more information on how to use MySQL, please refer to the MySQL documentation.

Conclusion

In this tutorial, you learned how to install MySQL 8 on Ubuntu 22.04. You can now use MySQL to store and manage your data.

related articles

Setup MySQL in Amazon Linux 2

MySQL Optimization

Atiqur Rahman

I am MD. Atiqur Rahman graduated from BUET and is an AWS-certified solutions architect. I have successfully achieved 6 certifications from AWS including Cloud Practitioner, Solutions Architect, SysOps Administrator, and Developer Associate. I have more than 8 years of working experience as a DevOps engineer designing complex SAAS applications.

Leave a Reply