How to install MySQL on Ubuntu 22.04
Ubuntu 22.04, being one of the latest stable releases, provides all the necessary tools to successfully install and configure MySQL. In this guide, we will cover the step-by-step process of installing MySQL 8.0 on Ubuntu 22.04, starting from system preparation and installation of necessary packages to basic security settings.Preparing the system
System preparation is an important step before installing MySQL on Ubuntu 22.04, which helps to ensure that the database is installed correctly and minimizes possible problems in the process. First, you need to update the system packages to ensure that all components are up to date. This can be done using a command that will update the list of available packages and install the latest versions of the installed programs:apt update
apt upgrade
MySQL server installation
Installing MySQL server on Ubuntu 22.04 is a process that can be accomplished in just a few steps, thanks to the convenience of the APT package manager. The first step is to install MySQL:apt install mysql-server
The powerful and high-performance database management system MySQL version 8.0 will be installed, which provides many new features and improvements over previous versions. One of the key features is improved performance, which allows you to process large amounts of data more efficiently.In addition, the new MySQL version offers enhanced JSON capabilities, improved replication mechanisms and faster queries thanks to index optimization. These innovations make MySQL v8.0 an ideal choice for both small projects and large enterprise solutions.
You can view the installed version of the database with the command:
mysql -V
The conclusion should be roughly as follows:mysql Ver 8.0.40-0ubuntu0.22.04.1 for Linux on x86_64 ((Ubuntu))Installing MySQL on Ubuntu 22.04 is simple and intuitive. In the following section, we will go through the step-by-step process of installing and configuring MySQL to work on your system.
You can check the status of the MySQL service with the following command:
systemctl status mysql
MySQL server configuration
When installing MySQL on Ubuntu 22.04, you should pay attention to the security configuration to make sure your database is protected from unauthorized access and vulnerabilities. After successfully installing MySQL, the first step in improving security is to run the script:mysql_secure_installation
This tool helps simplify the configuration process by guiding you through a series of questions that allow you to set a strong root password, remove anonymous user accounts, and disallow remote root login. In addition, the script allows you to remove a test database, which is often unnecessary in production environments and can expose your system to potential threats. It is also recommended to review user access rights and create special accounts with limited privileges appropriate to their needs, reinforcing the principle of least privilege. Finally, regularly updating your MySQL installation and monitoring security advisories will help maintain a secure database environment on your Ubuntu 22.04 system.To the question "Would you like to setup VALIDATE PASSWORD component?" we recommend to answer positively (Y). Next, you need to set the complexity of passwords. The recommended value is STRONG (2). Remove anonymous users: the question "Remove anonymous users?", the answer is "Y".
After that it is suggested to disable remote access for root superuser. Normally root should only have the right to connect from 'localhost'. This ensures that someone cannot pick up root's password from the network.
"Remove test database and access to it?" - remove test database and reset privileges. That's it.
Set the root user password for MySQL
When installing MySQL on Ubuntu 22.04, one important step is to set a password for the root user. This password serves as a security measure to ensure that only authorized users can access the database management system. It is recommended that you choose a password that is as secure as possible. Remember to keep this password private as it plays an important role in securing your MySQL server. After setting the password, you can continue with the remaining configuration steps to complete the installation of MySQL on Ubuntu 22.04.Let's enter the MySQL shell by executing the command:
mysql
Next, enter the SQL command:ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY 'secured_password';
where secured_password is your password.You can generate a good password at this link.
Next, we reset privileges and exit the MySQL:
FLUSH PRIVILEGES;
quit
And how to create a new MySQL user you can read in our article:
11 Dec 2024, 18:51:19