CentOS 7 Install MySQL5.7

#MySQL # server #CentOS date: 2021/2/22

Installation Mode Selection

As we all know, Linux is divided into RedHat system and Debian system, CentOS belongs to RedHat system

You can install the software in the following ways

  • RPM(RedHat Package Manager)
  • YUM(Yellow Dog Update Modified) mode
  • Source code compilation and installation

YUM is an improved version of RPM software manager. It solves the problem of software package dependency faced by RPM well. A lot of software dependency makes people’s head ache

Source code compilation and installation is more common, can add and delete their want or do not want the module, can be customized, suitable for all systems.

In this installation, I choose YUM to install MySQL

Preparations before Installation

Before installing any software, it’s a good idea to check its official documentation on the website. Most software comes with detailed documentation, especially open source software.

You can find detailed documentation on the MySQL website. Select the ones that meet your needs and click on them.

Dev.mysql.com/doc/refman/…

I’m installing MySQL5.7 on CentOS7 using YUM, so check out this document:

Dev.mysql.com/doc/refman/…

After going through it, you can start installing it.

Installation Procedure

Add MySQL YUM source

MySQL Yum Repository

Select the corresponding version. This system is CentOS7, so select Red Hat Linux7

Just click download, this source contains all versions of MySQL

I copied the download link and pasted it to the server for download

wget https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

Then install

sudo yum localinstall mysql80-community-release-el7-3.noarch.rpm

Check the source after installation, there are several versions 5.5, 5.6, 5.7, 8.0, but 5.7 is in the disabled state, now enable 5.7, disable 8.0

Disabling version 8.0

sudo yum-config-manager --disable mysql80-community

Enabling version 5.7

sudo yum-config-manager --enable mysql57-community

Look again. That’s what I wanted

If you’re a CentOS7 or older version, one more thing you need to do is disable the default MariaDB before starting the installation

CentOS7 can skip this step and just start installing, and yum will take care of the dependencies automatically

The installation

Sudo yum module disable mysql

And then you go all the way y

test

Start MySQL server

sudo service mysqld start

or

sudo systemctl start mysqld

I prefer to use the second one and then view the running status already in normal operation

The official documentation for MySQL provides the following guidance:

Query the temporary password, then use this temporary password to log in, and change the password as soon as possible

In some cases, you may not be able to change passwords using alter user ‘root’@’localhost’ indentified by ‘mynewpwd’

UPDATE mysql.user
	SET authentication_string = PASSWORD('MyNewPass'), password_expired = 'N'
	WHERE User = 'root' AND Host = 'localhost';
FLUSH PRIVILEGES;
Copy the code

Or do you log in with a temporary password, fail to change the password, and then try to log in again, but can not log in, use the following method can directly reset the password

Edit /etc/my.cnf, add skip-grant-tables to /etc/my.cnf, and restart mysqld

After the MySQL server is restarted, you do not need a password to log in to the MySQL server. Log in to the MySQL server, set the password, exit the MySQL server, comment out the new line in the configuration file, and restart the MySQL server

The official documentation suggests it’s best not to use this method to reset your password, as it can cause security issues, but I still feel it’s a rude and quick method, a small personal server, and no one is going to hack you. However, if it is a company production environment, it is best to follow the official advice to avoid losses.

As the official documentation indicates, some refinement work may be required after the installation is complete, but it is not necessary. Chapter 2 Installing and Upgrading MySQL 2.10 post-installation Setup and Testing includes the following details:

These perfect work basically can choose not to do, but you can also choose to read, basically can solve a large part of the usual use of the process encountered problems.