参考链接:https://blog.csdn.net/Sunny_Future/article/details/105345493
参考链接:https://dev.mysql.com/doc/refman/8.0/en/linux-installation-yum-repo.html
安装好依赖环境
yum install -y yum-utils wget
下载仓库包
wget https://dev.mysql.com/get/mysql80-community-release-el7-5.noarch.rpm
安装仓库包
# rpm -ivh mysql80-community-release-el7-5.noarch.rpm --no-check-certificate
# 解决报错如,Check that the correct key URLs are configured for this repository.
# rpm --import http://repo.mysql.com/RPM-GPG-KEY-mysql-2022
# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
更新 yum仓
yum makecache
查看可用版本
yum repolist all | grep mysql
默认开启最新版本enabled,需要改成需要的版本
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community 禁用
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - S 禁用
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community 禁用
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - S 禁用
mysql-cluster-8.0-community/x86_64 MySQL Cluster 8.0 Community 禁用
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - S 禁用
mysql-connectors-community/x86_64 MySQL Connectors Community 启用: 192
mysql-connectors-community-source MySQL Connectors Community - So 禁用
mysql-tools-community/x86_64 MySQL Tools Community 启用: 90
mysql-tools-community-source MySQL Tools Community - Source 禁用
mysql-tools-preview/x86_64 MySQL Tools Preview 禁用
mysql-tools-preview-source MySQL Tools Preview - Source 禁用
mysql55-community/x86_64 MySQL 5.5 Community Server 禁用
mysql55-community-source MySQL 5.5 Community Server - So 禁用
mysql56-community/x86_64 MySQL 5.6 Community Server 禁用
mysql56-community-source MySQL 5.6 Community Server - So 禁用
mysql57-community/x86_64 MySQL 5.7 Community Server 禁用
mysql57-community-source MySQL 5.7 Community Server - So 禁用
mysql80-community/x86_64 MySQL 8.0 Community Server 启用: 343
mysql80-community-source MySQL 8.0 Community Server - So 禁用
修改为需要的版本,我这里用5.7,即禁用yum存储库中mysql不需要的版本和开启需要的版本
yum-config-manager --disable mysql80-community
yum-config-manager --enable mysql57-community
查看需要的版本是否enabled
yum repolist all | grep mysql
mysql-cluster-7.5-community/x86_64 MySQL Cluster 7.5 Community 禁用
mysql-cluster-7.5-community-source MySQL Cluster 7.5 Community - S 禁用
mysql-cluster-7.6-community/x86_64 MySQL Cluster 7.6 Community 禁用
mysql-cluster-7.6-community-source MySQL Cluster 7.6 Community - S 禁用
mysql-cluster-8.0-community/x86_64 MySQL Cluster 8.0 Community 禁用
mysql-cluster-8.0-community-source MySQL Cluster 8.0 Community - S 禁用
mysql-connectors-community/x86_64 MySQL Connectors Community 启用: 192
mysql-connectors-community-source MySQL Connectors Community - So 禁用
mysql-tools-community/x86_64 MySQL Tools Community 启用: 90
mysql-tools-community-source MySQL Tools Community - Source 禁用
mysql-tools-preview/x86_64 MySQL Tools Preview 禁用
mysql-tools-preview-source MySQL Tools Preview - Source 禁用
mysql55-community/x86_64 MySQL 5.5 Community Server 禁用
mysql55-community-source MySQL 5.5 Community Server - So 禁用
mysql56-community/x86_64 MySQL 5.6 Community Server 禁用
mysql56-community-source MySQL 5.6 Community Server - So 禁用
mysql57-community/x86_64 MySQL 5.7 Community Server 启用: 584
mysql57-community-source MySQL 5.7 Community Server - So 禁用
mysql80-community/x86_64 MySQL 8.0 Community Server 禁用
mysql80-community-source MySQL 8.0 Community Server - So 禁用
安装mysql
yum install mysql-community-server -y
启动mysql
systemctl start mysqld
5.7版本mysql第一次启动自动生成临时密码,需要修改后才能正常使用
## 查看临时密码
# grep 'temporary password' /var/log/mysqld.log
## 登录mysql
# mysql -uroot -p
## 修改密码
# mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY '这里是密码';
Query OK, 0 rows affected (0.00 sec)
然后重启修改配置文件,datadir=/data/mysql
cp -r /var/lib/mysql /data/
chown -R mysql:mysql /data/mysql/
标签:禁用,mysql,Community,source,yum,community,版本,MySQL
From: https://www.cnblogs.com/wszzn/p/18140628