How to Install MySQL Server on Ubuntu 22.04?

Jul 13, 2022 . Admin

Hi Guys,

This article will provide some of the most important example How to Install MySQL Server on Ubuntu 22.04?. This post will give you simple example of Databases - MySQL - Ubuntu 22.04. I’m going to show you about Unable to install MySQL-server in Ubuntu. you will learn Step-by-step Installation MySOL for Ubuntu. follow bellow step for Install MySQL Server on Ubuntu 22.04.

You can use this post for ubuntu 14.04, ubuntu 16.04, ubuntu 18.4, ubuntu 20.04, ubuntu 21 and ubuntu 22.04 versions.

Step 1: Update System Dependencies

Press “CTRL+ALT+T” to open the terminal of the Ubuntu 22.04 and run the below-given command to update system repositories:

$ sudo apt update 
Step 2: Install MySQL

In the next step, install the MySQL on your system with the help of the following command:

$ sudo apt-get install mysql-server

Ensure that the server is running using the systemctl start command:

$ sudo systemctl start mysql.service

Now it’s time to import the Webmin GPG key for signing the packages in the repository:

output should show that the service is enabled and running:

(1). mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Fri 2022-04-29 00:38:45 UTC; 11s ago
    Process: 13836 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, statu>
   Main PID: 13844 (mysqld)
     Status: "Server is operational"
      Tasks: 38 (limit: 1151)
     Memory: 351.4M
        CPU: 1.043s
     CGroup: /system.slice/mysql.service
             └─13844 /usr/sbin/mysqld
Step 3: Securing MySQL

Run the security script with sudo:

sudo mysql_secure_installation

If you elect to set up the Validate Password Plugin, any MySQL user you create that authenticates with a password will be required to have a password that satisfies the policy you select:

Output
Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No: Y

Three levels of password validation policy, low, medium, and strong; is as follows:

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
STRONG Length >= 8, numeric, mixed case, special characters and dictionary file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:

The next prompt, will be asked to set a password for the MySQL root user.

Please set the password for root here.

Note that even though you’ve set a password for the root MySQL user, this user is not currently configured to authenticate with a password when connecting to the MySQL shell.

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :

Once the script completes, your MySQL installation will be secured. You can now move on to creating a dedicated database user with the MySQL client.

Step 4: Login to MySQL as root

The command, so you must invoke mysql with sudo privileges to gain access to the root MySQL user:

$ sudo mysql

Change the authentication type which helps you to login to your MySQL server as root using an external program such as phpMyAdmin.

We can do this using two methods listed below

Method 1: Create New user

the recommended option by creating a new dedicated administrative user with access to all databases:

CREATE USER 'sammy'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' WITH GRANT OPTION;
Method 2: Change Authentication Method
CREATE USER 'sammy'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';
#Ubuntu