Share your love
Easy Steps To Install MySQL on Ubuntu 22.04

This tutorial intends to teach you How To Install MySQL on Ubuntu 22.04. MySQL is an open-source SQL relational database management system that’s developed and supported by Oracle. It stores that information in separate “tables” and connects it with “keys”, which is why it’s relational.
YOu can now proceed to the following steps on the Orcacore website to set MySQL database management on Ubuntu 22.04.
Table of Contents
Steps To Install and Configure MySQL on Ubuntu 22.04
To Install MySQL on Ubuntu 22.04, you must log in to your server as a non-root user with sudo privileges. To do this, you can follow our guide on Initial Server Setup with Ubuntu 22.04.
1. Install MySQL on Ubuntu 22.04
First, you need to update your local package index with the following command:
sudo apt update
Then, use the following command to install the MySQL server:
sudo apt install mysql-server -y
Start and Enable MySQL Server
When your installation is completed, start and enable your MySQL service on Ubuntu:
# sudo systemctl start mysql.service
# sudo systemctl status mysql.service
Confirm that your service is active and running:
sudo systemctl status mysql.service

2. Configure MySQL on Ubuntu 22.04 | Set MySQL Root Password
When you want to run the MySQL secure script on Ubuntu, you will get an error. The reason is that this script will attempt to set a password for the installation’s root MySQL account but, by default on Ubuntu installations, this account is not configured to connect using a password.
To resolve this, log in to your MySQL shell:
sudo mysql
Then run the following ALTER USER command to change the root user’s authentication method to one that uses a password:
mysql>
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
After making this change, exit the MySQL prompt on Ubuntu 22.04:
mysql> exit
Run MySQL Secure Installation Script
Following that, you can run the mysql_secure_installation script without issue.
sudo mysql_secure_installation
The first prompt will ask whether you’d like to set up the Validate Password Plugin, which can be used to test the password strength of new MySQL users before deeming them valid.
From there press Y to continue.
When you are done, you access your mySQL shell by using the password you have created:
sudo mysql -u root -p
If you want to connect to MySQL as your root user using the sudo mysql
command, you can run the command below from your MySQL shell:
mysql> ALTER USER 'root'@'localhost' IDENTIFIED WITH auth_socket;
That’s it, you are done.
Conclusion
At this point, you have learned to Install and Configure MySQL on Ubuntu 22.04. MySQL Server on Ubuntu 22.04 is used for database management, storing, organizing, and retrieving structured data efficiently.
Please subscribe to us on Facebook, Instagram, and YouTube.
You may also like these articles:
Reset MySQL And MariaDB Root Password on Ubuntu 22.04
How To Enable TCP BBR on Ubuntu 22.04
How To Install 7-zip on Ubuntu 22.04
FAQs
Why use MySQL Server on Ubuntu 22.04?
It is lightweight, secure, and scalable, making it ideal for web applications, enterprise databases, and cloud-based storage.
Where is the MySQL configuration file located?
The main configuration file is /etc/mysql/mysql.conf.d/mysqld.cnf.
What should I do if MySQL fails to start?
You can check logs with the following command:sudo journalctl -u mysql --no-pager | tail -20
How do I check if MySQL is running?
You can easily use the command below:systemctl status mysql