centos 8.0以上版本安装MySQL5.7版本

首先禁用MySQL默认的AppStream存储库:

sudo dnf remove @mysql
sudo dnf module reset mysql && sudo dnf module disable mysql

 

1、centos8没有MySQL存储库,因此我们将使用centos 7存储库。创建一个新的存储库文件。

sudo vim /etc/yum.repos.d/mysql-community.repo

 

2、将以下数据插入上面的存储库中

[mysql57-community]
name=MySQL 5.7 Community Server
baseurl=http://repo.mysql.com/yum/mysql-5.7-community/el/7/$basearch/
enabled=1
gpgcheck=0

[mysql-connectors-community]
name=MySQL Connectors Community
baseurl=http://repo.mysql.com/yum/mysql-connectors-community/el/7/$basearch/
enabled=1
gpgcheck=0

[mysql-tools-community]
name=MySQL Tools Community
baseurl=http://repo.mysql.com/yum/mysql-tools-community/el/7/$basearch/
enabled=1
gpgcheck=0

 

3、安装MySQL(这里我选择MySQL5.7)
sudo dnf –enablerepo=mysql57-community install mysql-community-server

4、下载完成后检查版本
[root@test ~]# rpm -qi mysql-community-server

Name : mysql-community-server
Version : 5.7.29
Release : 1.el7
Architecture: x86_64
Install Date: Sat 22 Feb 2020 11:04:07 AM CST
Group : Applications/Databases
Size : 801919839
License : Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved. Under GPLv2 license as shown in the Description field.
Signature : DSA/SHA1, Thu 19 Dec 2019 04:12:40 PM CST, Key ID 8c718d3b5072e1f5
Source RPM : mysql-community-5.7.29-1.el7.src.rpm
Build Date : Wed 18 Dec 2019 09:31:48 PM CST
Build Host : loki02.no.oracle.com
Relocations : (not relocatable)
Packager : MySQL Release Engineering <mysql-build@oss.oracle.com>
Vendor : Oracle and/or its affiliates
URL : http://www.mysql.com/
Summary : A very fast and reliable SQL database server
出现以上信息说明成功

5、检查 mysql 源是否安装成功
yum repolist enabled | grep “mysql.*-community.*”

出现以下信息说明安装成功:
mysql-connectors-community MySQL Connectors Community 141
mysql-tools-community MySQL Tools Community 105
mysql57-community MySQL 5.7 Community Server

6、启动MySQL
systemctl start mysqld

7、查看启动状态
systemctl status mysqld

8、刷新所有修改过的配置文件
systemctl daemon-reload

9、获取安装mysql后生成的临时密码,用于登录
grep ‘temporary password’ /var/log/mysqld.log

10、登录MySQL
mysql -uroot -p

11、修改登录密码
mysql>
set global validate_password_policy=0;
set global validate_password_mixed_case_count=0;
set global validate_password_number_count=3;
set global validate_password_special_char_count=0;
set global validate_password_length=3;

mysql> set password for ‘root’@’localhost’=password(‘123456’);

0
显示验证码