Get 50% Discount Offer 7 Days


Contact Info

Chicago 12, Melborne City, USA

+88 01682648101

[email protected]

The best way to Install MySQL on Ubuntu 22.04

In today’s developing world and big data ecosystem, MySQL has become one of the most well-known technologies and is one of the most popular databases in many industries. If you want to master this database, you only need a basic understanding. MYSQL can be used on various Linux distributions and one of these distros is Ubuntu. Here, we will be going to show the best way to install MYSQL on Ubuntu 22.04. Keep studying carefully.

How to Install MySQL on Ubuntu 22.04

MySQL is an open-source database management system that is usually installed as a part of the popular LAMP stack. As you learn how to install MySQL, you will have a working relational database to build your next website or application. Now, follow the instructions step-by-step to install MySQL on Ubuntu Linux VPS.

How to install MySQL on Ubuntu

Prerequisites to Install MySQL

To install MySQL you will need the following requirements:

  • A Linux VPS with Ubuntu OS.
  • A non-root administrative user
  • A firewall configured with UFW

Installing MySQL on Ubuntu

To start the installation process, first of all, you should update the system repository. Press CTRL+ALT+T to open a terminal on Ubuntu. Now run the command below to update the system repository:

sudo apt update

Now you can run the following command to install MySQL on your system:

sudo apt-get install mysql-server

You need a few minutes to complete the installation and continue.

Note that you can verify MySQL status using the following command:

 systemctl is-active MySQL

The installation was straightforward and simple. So you can configure it on your system.

Configuring MySQL on Ubuntu

If you want to perform an initial and interactive configuration of your MySQL server, you can execute the command line below:

sudo mysql_secure_installation

At the beginning of the configuration step, you will be asked to set the level for the password validation policy. So, according to your validation requirements, choose a number from the menu in front of you.

configuring MySQL

Now enter the new password for root and press Y to continue the process with your new password:

configuration of MySQL 2

Finally, do the rest of the configuration section accordingly:

final part to configure mysql

Login to MySQL on Ubuntu

Now, create a native password for the root by logging into the MySQL server and setting the default authentication method to “mysql_native_password”:

 sudo MySQL

Now you will see a query that sets the root password to “Password123#@!” and determines the authentication method to “mysql_native_password“:

ALTER USER 'root'@'localhost'
IDENTIFIED WITH mysql_native_password BY 'Password123#@!';

To be able to apply the changes without restarting the MySQL service, you can reload the grant table in the MySQL database:


Now, you can login to the MySQL server with your new password and enjoy the server.

login mysql

Now that you have installed MySQL successfully, you can ensure MySQL service is active and running with the following command:

systemctl status mysql.service

That’s it! Login to MySQL and use this great database as you wish.

Troubleshooting Some Common Issues of MySQL on Ubuntu

Like any software, it can encounter various issues. Here are some common issues with MySQL on Ubuntu and their potential solutions:

1- You cannot connect to the MySQL server.


  • Ensure that MySQL is running: sudo service mysql status.
  • Check if MySQL is bound to the correct IP address and port.
  • Check for firewall rules blocking MySQL connections.

2- You’ve forgotten the MySQL root password.


Stop MySQL:

sudo service mysql stop.

Start MySQL in safe mode:

sudo mysqld_safe --skip-grant-tables.

Connect to MySQL:

mysql -u root.

Change the root password:

UPDATE mysql.user SET authentication_string = PASSWORD('new_password') WHERE User = 'root'; FLUSH PRIVILEGES;.

Stop MySQL safe mode:

sudo service mysql stop.

3- Your MySQL database is corrupted.


  • Create a backup of your data.
  • Try repairing the database: mysqlcheck -r -u username -p dbname.
  • If the repair fails, restore from the backup.

4- Running out of disk space can cause MySQL to stop working.


  • Identify and delete unnecessary data or log files.
  • Resize your server or storage volume.

5- MySQL fails to start


  • Check the MySQL error log for the cause of the failure.
  • Ensure no other services are using the MySQL port.
  • Repair or reinstall MySQL if necessary.


As mentioned, MySQL is a popular database. In this article, we examined how to install it in Ubuntu and explained to you from updating the repositories to configuring and running it. So that you can enter the MySQL server by setting a new password and using it. We hope that the above information is useful for you. Happy coding!

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Share this Post

Leave a Reply

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