Ubuntu

How to Install MySQL on Ubuntu 22.04?

How To Install MySQL on Ubuntu 22.04

MySQL is a popular and free-to-use Relational Database Management System (RDBMS) technology for structured data focused on Structured Query Language (SQL). MySQL allows users to access, manage, store in a well-structured format, manipulate, and retrieve data.

This article will demonstrate installing MySQL on Ubuntu 22.04 LTS by following steps:

  • Update System Repositories
  • Install MySQL
  • Verify Installation
  • Configuration of MySQL Server
  • Log in to MySQL Server

How to Install, Configure, and Setup MySQL on Ubuntu 22.04?

In order to install MySQL, the following steps will be performed:

Step 1: Update System Repositories

To update system packages, launch the terminal by pressing a combination of [Ctrl + Alt + T] and then execute the following command:

$ sudo apt update

Step 2: Install MySQL

Executing the below-stated command will install the MySQL on Ubuntu 22.04 LTS:

$ sudo apt install mysql-server

Hit the “Y” key to proceed with the MySQL installation.

The installation process will take a few moments to complete depending upon your internet connection.

Successful installation of MySQL can be verified from the above screenshot.

Step 3: Verify Installation

MySQL installation can be verified by checking the version of MySQL. For this purpose, execute the following command:

$ mysql --version

We can run the following command to ensure MySQL service is active:

$ systemctl status mysql.service

From the above image, it can be seen that MySQL is active and running.

Step 4: Configuration of MySQL

MySQL is configured by running the below command:

$ sudo mysql_secure_installation

Enter the password for the user and press “y” in order to continue with the installation.

The user will be asked to set a secure password. There are three levels: low, medium, and strong. A user can choose the level of security based on their requirements.

The user is then prompted to delete anonymous users. A user can select “yes” or “no” options according to their requirements.

The user is then prompted to disallow root login remotely which a user can select based on their requirements.

Similarly, a user can set other configuration options according to their requirements.

This concludes the configuration. Next, we will log in to the MySQL server.

Step 5: Log in to MySQL Server

To log in to the MySQL server, a user can execute the following command:

$ sudo mysql

Various tasks can be performed in MySQL, like users accessing, managing, storing, manipulating, and retrieving data. Some basic operations in MySQL can be seen on: How to Run MySQL in Linux/Ubuntu Terminal?

Finally, the following command is used to exit MySQL

$ mysql> exit

How to Uninstall MySQL?

If MySQL is no longer needed and you want to free up the space on your Ubuntu machine, then you can remove it by executing the following steps:

Step 1: Stop MYSQL Services

MySQL has background services. Therefore, before uninstalling MySQL, first, the background services must be stopped by executing the following command:

$ sudo systemctl stop mysql

The “systemctl” command will stop MySQL. Next, MySQL essentials are removed.

Step 2: Remove MySQL Essentials

MySQL essentials, such as MySQL client, server, server-core, and client-core packages can be removed by executing the following “sudo” command:

$ sudo apt purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*

Press “Y” to continue with the uninstalling process.

From the above image, it can be seen that MySQL files are removed.

Step 3: Remove MySQL Associated Files

The remaining files associated with MySQL are removed from the directories by executing the “sudo rm” command as follows:

$ sudo rm -rf /etc/mysql /var/lib/mysql /var/log/mysql

Step 4: Remove Additional Packages

Additional SQL packages are removed by:

$ sudo apt autoremove

Press “Y” to continue with the uninstallation process.

The uninstallation of mySQL can be verified by running the following command:

From the above image, it can be observed that MySQL is uninstalled successfully.

Conclusion

To Install MySQL, first, update the apt repository, then execute the “sudo apt install mysql-server” command. After installation, MySQL can be configured using the “sudo mysql_secure_installation” command. Finally, we can run MySQL on Terminal using the “sudo mysql” command. This article has demonstrated installing MySQL on Linux/Ubuntu 22.04 LTS.

Similar Posts