How to install MySQL on Ubuntu 22.04?
Overview
MySQL is among one of the most extensively used and well-known open-source relational database management systems and is frequently installed as an element of the well-known LAMP stack. It employs SQL to handle its data and implements the relational paradigm. This tutorial guides you through setting up MySQL 8.00 on a server running Ubuntu version 22.04.
Prerequisites
There are certain prerequisites that need to be met before you begin.
Ubuntu 22.04-equipped system
A sudo-privileged user account
Internet connection
Get Started
Step 1: Upgrade and Update the Repository Package
To make sure you're installing the most recent version available of MySQL, update the system package repository.
Run the following command on your terminal and type in your password when requested, then wait for the update to complete.
Next, run the following command and enter Y when prompted to proceed with the upgrade, then hit ENTER. Wait for the upgrade to conclude.
Step 2: Install MySQL
After the package repository has been properly updated, use the command below to install MySQL Server:
Optional: Run the following commands to see if MySQL was successfully installed:
The output indicates the version of MySQL that is set up on the computer.
Step 3: Configuring MySQL
Open the MySQL prompt.
To switch the root user's authentication mechanism to one which utilizes a password, run the following command:
Exit the MySQL prompt after making these modifications by using the following command:
Step 4: Securing MySQL
Immediately after installation, the MySQL instance on your computer is insecure.
Run the security script provided to secure your MySQL user account with password authentication:
You do not need to change the password since you have already used the ALTER USER
command to switch the root user's authentication mechanism to one that utilizes a password provided by you in step 3.
The following security characteristics are then requested by the script:
For each of these questions, selecting Y is advised. But you may input any other key if you desire a different configuration for whatever reason.
Step 5: Check if the MySQL server is running
The MySQL service launches automatically when MySQL has been installed successfully.
Run the following command to check that the MySQL server is up and running:
Step 6: Log in to the MySQL server
After the security script is finished, you can restart MySQL and set the root user's authentication protocol back to auth socket, which is the default. Use the following command to log in as the root user with a password:
When prompted for a password, use the one set up in Step 3.
Use this command to return to using the default authentication method after that:
As a result, you can execute the sudo mysql command to reconnect to MySQL as your root user.
Finally, use the following command to log into the MySQL interface:
You can now use your new MySQL configuration to run queries, build databases, and test them out.
Conclusion
Now that you should have successfully installed a MySQL server on your computer, you can begin studying MySQL's extensive potential and testing out its many features.
Last updated