On the Linux operating system, the MySQL database is a very popular relational database. There may be many ways to install a MySQL database, one of which is to install MySQL through an RPM package. RPM is a software package manager used to install, upgrade and remove software packages on the Red Hat base operating system. This article will introduce how to install MySQL on a Linux system using RPM packages.
First, we need to download the RPM package for our operating system from the MySQL official website. It is important to choose the right RPM package, especially one that is compatible with the operating system and version. Now we assume that we are installing the CentOS 7 operating system, so we need to select the RPM package for CentOS 7.
After downloading the RPM package, we can use the following command to install it:
sudo rpm -ivh <path-to-RPM-package>
where<path- to-RPM-package>
is the path to the RPM package we downloaded. For example, if we download the RPM package into the ~/Downloads
folder, then we will install it using the following command:
sudo rpm -ivh ~/Downloads/mysql57-community-release-el7-9.noarch.rpm
During the installation process, we will see some output, Such as:
Preparing... ################################# [100%] Updating / installing... 1:mysql57-community-release-el7-9 ################################# [100%]
This means that we have successfully installed the MySQL RPM package.
The MySQL RPM package contains a package named mysql-community-server
, which contains the MySQL server all content. Therefore, we can use the following command to install the MySQL server:
sudo yum install mysql-community-server
After installing the MySQL server, we need to use the following command to start the MySQL service:
sudo systemctl start mysqld
At this point, the MySQL server will be up and running.
After installing and starting the MySQL server, we need to verify that it is available. We can use the following command to check whether the MySQL server has been installed correctly:
sudo systemctl status mysqld
This will output the status information of the MySQL server. If the MySQL server is properly installed and running, we should be able to see the following output:
● mysqld.service - MySQL Community Server Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled) Active: active (running) since Fri 2021-05-07 14:43:49 CST; 3s ago Process: 3707 ExecStartPre=/usr/bin/mysqld_pre_systemd (code=exited, status=0/SUCCESS) Main PID: 3709 (mysqld) Status: "Server is operational" CGroup: /system.slice/mysqld.service └─3709 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid
This indicates that the MySQL server is running and ready for use.
After installing the MySQL server, we need to set the password of the MySQL root user. We can use the following command to set the password:
sudo mysql_secure_installation
This command will start the MySQL Secure Installation Wizard, which will prompt us to enter a new password. After entering the password, we need to follow the prompts to make some other settings, such as disabling anonymous access and deleting the test database.
After installing and setting up the MySQL server, we can log in to the MySQL database using the following command:
mysql -u root -p
This command will prompt us to enter The password of the MySQL root user. After entering the password, we will enter the MySQL Shell where we can execute MySQL commands and queries.
Now we have successfully installed the MySQL database on the Linux system using the RPM package. You can also use RPM packages to install MySQL databases on other operating systems such as Ubuntu, Debian, and Fedora. Before installing MySQL, make sure to select the correct RPM package for the operating system you are using, and make sure to follow the appropriate installation, startup, and setup guidelines.
The above is the detailed content of How to install MySQL on Linux system using RPM package. For more information, please follow other related articles on the PHP Chinese website!