Home  >  Article  >  Database  >  How to use rpm to install mysql on centos

How to use rpm to install mysql on centos

PHPz
PHPzOriginal
2023-04-21 11:23:19544browse

Use rpm package to install MySQL under CentOS/RHEL system

MySQL is one of the most popular open source relational database management systems. It supports multiple operating systems and programming languages ​​and has excellent performance. and reliability. CentOS/RHEL Linux is one of the most widely used Linux distributions in the open source community, so they are widely used to run MySQL services. This article will introduce how to use rpm packages to install MySQL on CentOS/RHEL systems.

Step 1: Download the MySQL rpm package

Before starting the installation, you need to visit the MySQL official website and download the latest version of MySQL from the download page. Select the version you need and download the rpm package for that version. Usually you need to download the MySQL client and server rpm packages. In this example, we will use MySQL5.7 version for demonstration.

cd /usr/local/src/
wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

Steps Two: Install the MySQL rpm package

After the download is completed, you need to use the rpm command as the root user to install the MySQL client and server rpm packages.

rpm -ivh mysql57-community-release-el7-11.noarch.rpm

After the installation is complete, you need to update all installed packages to ensure that our system packages are the latest version , and uses MySQL 5.7 as the default yum repository.

yum update

Step 3: Install MySQL server

Before installing the client, we need to install the MySQL server first. Use the command below to install MySQL server.

yum install mysql-server

After the installation starts, you will be prompted for confirmation and you can press the y key to continue installing the MySQL server. After the MySQL server is installed, you can use the systemctl command to start MySQL.

systemctl start mysqld

At this point, you can use the following command to check whether the MySQL server is running.

systemctl status mysqld

Step 4: Install the MySQL client

After the MySQL server is successfully installed, we can start installing the MySQL client. Run the following command to install the client into your system.

yum install mysql

After executing this command, you will have MySQL installed in your system. Once the installation is complete, you can access the MySQL server using the mysql command in the terminal.

mysql -u root -p

Step 5: Configure MySQL

After installing and running MySQL, we need to set the root password for the server and protect its security. To set the root password, run the following command.

mysql_secure_installation

When running this command, you will be prompted to follow the steps below to set the MySQL root password.

  1. Enter your current root password, if you have not set a root password, you can press Enter to skip this step.
  2. Do you want to set a new password? If so, enter your new password.
  3. Confirm the new password.
  4. Delete anonymous user (Y).
  5. Disable root remote login (Y). (Allows local access to MySQL server only)
  6. Delete the test database (Y).
  7. Reload the privilege table (Y).

After completing the above steps, the root password will be set and the MySQL server will be secured.

Conclusion

Using the above steps, you can use the rpm package to install MySQL on a CentOS/RHEL system and perform basic configuration and protection. It's a quick and easy installation that enables you to access and secure your MySQL server via the command line interface.

The above is the detailed content of How to use rpm to install mysql on centos. 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