CentOS is a distribution version of the Linux operating system, which is widely used in enterprise-level servers, cloud computing platforms and other fields. MySQL is a popular relational database management system that also plays an important role in enterprise-level applications. This article will introduce how to use the yum command to install and configure MySQL in CentOS systems.
1. Install yum
Yum is an automated tool provided by CentOS to facilitate software package management. It can easily obtain and install software packages from the official warehouse. Before using the yum command, you need to install yum first.
1. Check whether yum has been installed
You can check whether yum has been installed in the system by entering the following command:
yum repolist
If yum has been installed, you will see Output information similar to the following:
repo id repo name status base CentOS-6 - Base 6,706 extras CentOS-6 - Extras 62 updates CentOS-6 - Updates 328
2. Install yum
If yum is not installed in the system, you can install it through the following command:
sudo yum install yum
2. Install MySQL
Before installing MySQL, you need to determine the CentOS system version and CPU architecture. You can use the following command to check:
uname -a
There are two ways to install MySQL: one is to add a third-party warehouse. Installation, the other is to install through the official source. These two methods will be introduced below.
1. Install MySQL through a third-party warehouse
The third-party warehouse refers to the software warehouse not officially provided by CentOS, because it usually contains new versions of software packages, and the official CentOS warehouse The software version is relatively old. Before using a third-party warehouse, you need to configure it. Taking the yum source officially provided by MySQL as an example, the configuration method is as follows:
a. Download the yum source configuration file of mysql:
sudo wget https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
Note: If you need other versions of MySQL, you can change the above command Change 57 in to other version numbers
b. Install the yum source configuration file
sudo rpm -ivh mysql57-community-release-el7-11.noarch.rpm
c. Check the yum source of mysql
sudo yum repolist enabled | grep "mysql.*-community.*"
If the following content is output, it means that it has been Successfully added the yum source of mysql:
mysql-connectors-community/x86_64 MySQL Connectors Community 16 mysql-tools-community/x86_64 MySQL Tools Community 49 mysql57-community/x86_64 MySQL 5.7 Community Server 385
d. Install MySQL
sudo yum install mysql-server
2. Install MySQL through the official source
By default, there is no official CentOS source Integrate the MySQL package, so the official source needs to be added manually. The following are the steps to add official sources and install MySQL:
a. Back up the system yum source
Back up the system yum configuration file before adding external sources
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
b. Manual editing /etc/yum.repos.d/CentOS-Base.repo
In the CentOS-Base.repo configuration file, add the following content:
[mysql-connectors-community] name=MySQL Connectors Community baseurl=https://repo.mysql.com/yum/mysql-connectors-community/el/6/$basearch/ enabled=1 gpgcheck=1 gpgkey=https://repo.mysql.com/RPM-GPG-KEY-oracle [mysql-tools-community] name=MySQL Tools Community baseurl=https://repo.mysql.com/yum/mysql-tools-community/el/6/$basearch/ enabled=1 gpgcheck=1 gpgkey=https://repo.mysql.com/RPM-GPG-KEY-oracle [mysql57-community] name=MySQL 5.7 Community Server baseurl=https://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/ enabled=1 gpgcheck=1 gpgkey=https://repo.mysql.com/RPM-GPG-KEY-oracle
Note: If you need 6.x version of CentOS system, the el/6/ of baseurl needs to remain unchanged; if it is a 7.x version of CentOS system, el/6/ needs to be changed to el/7/
c. Update yum cache
sudo yum makecache
d. Install MySQL
sudo yum install mysql-server
Note: When installing MySQL, its dependency packages and related development files will be automatically installed
3. Start and configure MySQL
After completing the installation of MySQL, you need to start it and perform the necessary configurations.
1. Start MySQL
Use the following command to start MySQL:
sudo service mysqld start
If the startup fails, you can view the log file and troubleshoot:
sudo tail /var/log/mysqld.log
2 , Configure MySQL
a. Log in to MySQL
Use the following command to log in to MySQL:
mysql -u root -p
Enter the initial password to log in to the MySQL shell.
b. Change the initial password
When you log in to the MySQL shell for the first time, you need to change the default password. Use the following command to change the password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'newpassword';
where newpassword is the new password, which can be set as needed.
c. Configuring MySQL
In MySQL, various parameters are implemented by modifying the configuration file. The following are several common configuration items:
After modifying the configuration file, you need to restart MySQL to take effect:
sudo service mysqld restart
So far, we have completed the process of installing and configuring MySQL using the yum command in the CentOS system.
The above is the detailed content of centos mysql yum installation. For more information, please follow other related articles on the PHP Chinese website!