Home  >  Article  >  Database  >  How to use RPM package to install MySQL in Linux

How to use RPM package to install MySQL in Linux

PHPz
PHPzOriginal
2023-04-19 14:12:071255browse

There are different ways to install MySQL in a Linux environment, but in this article we will focus on a specific way, which is installation through RPM packages. RPM (Red Hat Package Manager) is a convenient way to manage and distribute software in Linux systems. It supports automatic installation and uninstallation. It is based on RPM packages and can be used in different Linux distributions.

In this article, we will introduce how to use RPM packages to install MySQL in a Linux system. We will also provide some practical tips and suggestions to ensure that you install MySQL successfully using this method.

Step 1: Check whether MySQL is installed in the system

Before starting the installation of MySQL, first check whether MySQL has been installed in the current system. You can check whether MySQL has been installed in the system by executing the following command:

rpm -qa | grep mysql

If you see any components of MySQL in the system, it means that your MySQL has been installed on the system. If there is no output, it means MySQL is not installed in your system and you can continue to the next step.

Step 2: Download the RPM package

Before installing MySQL, we need to download the RPM package applicable to your Linux distribution from the MySQL official website. You can use the following link to visit the MySQL official website:

https://dev.mysql.com/downloads/mysql/

At the bottom of the page, you can find different MySQL versions, choose yours Linux distribution and corresponding operating system version. After the download is complete, you need to enter the directory where the downloaded file is saved.

Step 3: Install MySQL

Once you have downloaded the MySQL RPM package and entered the relevant directory, you can start installing MySQL. The easiest way is to use the following command:

sudo rpm -ivh mysql-community-xxxx.rpm

Here "xxxx" represents the MySQL version number you downloaded. By running the above command, you will start the MySQL installer and install MySQL in your system.

However, before installing MySQL, you need to install some libraries and components that MySQL depends on, such as libaio and openssl. If you are missing any one dependency, MySQL's installer will not be able to proceed. If you are prompted that a dependency is missing, please use the following command to install its required dependencies:

sudo yum install libaio

sudo yum install openssl

After successfully installing the dependencies , you will be able to install MySQL in your system.

Step 4: Configure MySQL

After successfully installing MySQL, you need to do some configuration to run it correctly. You can start MySQL through the following command:

sudo systemctl start mysqld

At the same time, you also need to disable the firewall (it also needs to be set), otherwise it may affect your connection to MySQL. However, you can open the port, allowing access to MySQL, with the following command:

sudo firewall-cmd --permanent --zone=public --add-port=3306/tcp

sudo firewall-cmd --reload

After completing the basic MySQL configuration, you will need to execute the following command to complete the other configuration of MySQL:

sudo mysql_secure_installation

This command You will be provided with additional security options for MySQL, such as changing the MySQL administrator password, removing anonymous users, and restricting requests for remote access to MySQL. During this operation, you will answer a few questions and enter relevant details to ensure the security of MySQL.

Step Five: Verify MySQL Installation

Once MySQL is installed and configured, you need to perform some basic tests to ensure that the MySQL installation is successful. You can use the following command to test:

mysql -u root -p

Here, "root" represents the name of the MySQL user with full permissions. You will need to enter your MySQL administrator password to ensure you have full access to MySQL.

Once you have successfully accessed MySQL, you can use various MySQL commands for testing and operation. For example, you can use the following command to display the version of MySQL that is installed:

SELECT @@version;

Finally, you can use the following command to quit MySQL:

quit;

Summary

Installing MySQL through RPM packages is a relatively simple process, but it may require some specific configurations and operations to ensure the security and availability of MySQL. This article introduces the detailed steps for installing MySQL using RPM packages in a Linux environment, as well as some practical tips and suggestions to ensure that you can successfully install and configure MySQL during this process.

The above is the detailed content of How to use RPM package to install MySQL in Linux. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn