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:
Step 2: Install MySQL
Executing the below-stated command will install the MySQL on Ubuntu 22.04 LTS:
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:
We can run the following command to ensure MySQL service is active:
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:
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:
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
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:
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:
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:
Step 4: Remove Additional Packages
Additional SQL packages are removed by:
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.