This tutorial intends to teach you How To Install and Configure 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.
Steps To Install and Configure MySQL on Ubuntu 22.04
To complete this guide, 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.
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
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
Output ● mysql.service - MySQL Community Server Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset:> Active: active (running) since Thu 2022-11-10 09:58:32 UTC; 1min 2s ago Main PID: 3148 (mysqld) Status: "Server is operational" Tasks: 38 (limit: 4575) Memory: 364.0M CPU: 2.237s CGroup: /system.slice/mysql.service └─3148 /usr/sbin/mysqld ...
Configure MySQL on Ubuntu 22.04
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:
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:
Following that, you can run the mysql_secure_installation script without issue.
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.
At this point, you have learned to Install and Configure MySQL on Ubuntu 22.04.
You may be like these articles: