Site icon DesignLinux

How to Install MySQL on Ubuntu 22.04

how-to-install-mysql-on-ubuntu-22-04

MySQL is widely used and popular open-source database management system. MySQL installation on Ubuntu is very easy and it’s commonly being a part of the popular LAMP and LEMP stacks. This article shows you how to install MySQL on Ubuntu 22.04 systems.

How to Install MySQL on Ubuntu 22.04

Perform the following steps as root or sudo user to install MySQL on Ubuntu 22.04 system. At the time of writing this article, the latest Mysql version is 8.0.31 available in the Ubuntu repositories.

Step 1 – Update System Repositories

First, you need to update the index list using below command:

sudo apt update

Step 2 – Install Mysql

In next step, run the below command to install MySQL:

sudo apt install mysql-server

Installation process may take few minutes and It will ask you to set MySQL root user password. MySQL service will start automatically upon the installation complete.

Step 3 – Verify MySQL Installation

You can verify the installation by checking whether the MySQL server is running or not. Issue below command to verify it:

sudo systemctl status mysql

It should show below output if service is active:

● mysql.service - MySQL Community Server
      Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
      Active: active (running) since Thr 2022-11-24 01:25:44 UTC; 5min 7s ago
    Main PID: 6260 (mysqld)
      Status: "Server is operational"

Step 4 – Secure MySQL Installation

In this step we will execute MySQL inbuilt security script to improve MySQL security. Execute the mysql_secure_installation command:

sudo mysql_secure_installation

It will prompt you to enter root user password which you set before this step. After that, it will ask you to choose whether to use the VALIDATE PASSWORD PLUGIN or not, which can be used to test the strength of your MySQL password. Press ENTER if you don’t want to set up the validate password plugin.

Next, It will ask if you want to change current root user password. If your current password is perfect then, enter N for No at the prompt.

Now, for all next questions press Y and hit Enter key for each. This will remove some anonymous users and test database, disable remote root logins and load these new rules so that MySQL immediately respects the changes you have made. Following questions will be prompted and you have to press yes/y for all :

Remove anonymous users? (Press y|Y for Yes, any other key for No) : y
Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y
Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y
Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y

Step 5 – Connect to MySQL

You can login to MySQL server using command line using below command:

mysql -u root -p

It will prompt to enter root user password which you set before and it will show you output as below:

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 12
Server version: 8.0.31 MySQL Community Server - GPL

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Conclusion

It’s very straightforward to to install MySQL and Secure MySQL on Ubuntu 22.04 Jemmy Jellyfish system.

If you are facing any issue, feel free to leave a comment below.

Exit mobile version