centos7 二进制安装MySQL8(精简版)

一、下载MySQL8安装包

1、wget从官网拉取压缩包:wget https://cdn.mysql.com/archives/mysql-8.0/mysql-8.0.28-1.el7.x86_64.rpm-bundle.tar
2、上传提前下载的安装包到服务器上进行解压安装

在这里插入图片描述

上述两种办法取其一即可!!!!!!!!!!!!!!!!!!!!!!!

二、安装MySQL

1、在安装MySQL之前呢,先将系统内自带的mariadb安装包卸载掉,以防数据库冲突!!!

rpm -aq | grep mariadb

在这里插入图片描述

强制卸载自带的mariadb

rpm -e --nodeps mariadb-libs

2、解压MySQL安装包

在这里插入图片描述

解压之后会有很多rpm安装包,只安装我们所需要的即可

rpm -ivh mysql-community-common-8.0.28-1.el7.x86_64.rpm 
rpm -ivh mysql-community-client-plugins-8.0.28-1.el7.x86_64.rpm 
rpm -ivh mysql-community-libs-8.0.28-1.el7.x86_64.rpm 
rpm -ivh mysql-community-client-8.0.28-1.el7.x86_64.rpm 
rpm -ivh mysql-community-icu-data-files-8.0.28-1.el7.x86_64.rpm 
rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm 

发现载安装最后一个的时候有报错,是缺少环境导致的。我们先安装一下环境在尝试部署
[root@mysql ~]# rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm
warning: mysql-community-server-8.0.28-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
error: Failed dependencies:
/usr/bin/perl is needed by mysql-community-server-8.0.28-1.el7.x86_64
net-tools is needed by mysql-community-server-8.0.28-1.el7.x86_64
perl(Getopt::Long) is needed by mysql-community-server-8.0.28-1.el7.x86_64
perl(strict) is needed by mysql-community-server-8.0.28-1.el7.x86_64

yum install net-tools* -y
yum install pery -y

安装完后在部署 ”rpm -ivh mysql-community-server-8.0.28-1.el7.x86_64.rpm “ 就行了

三、环境配置

1、初始化数据库

mysqld --initialize --console

2、赋予权限

chown -R mysql:mysql /var/lib/mysql

3、启动数据库

systemctl start mysqld

4、查看数据库初始化密钥

cat /var/log/mysqld.log | grep localhost

在这里插入图片描述

5、登录数据库同时修改密码

在这里插入图片描述

alter user 'root'@'localhost' identified by 'password';

6、再次重新登陆即可