0.查看当前系统版本

#查看当前操作系统版本
(base) ➜ ~ cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)
#查看系统内核版本
(base) ➜ ~ uname -sr
Linux 3.10.0-1062.18.1.el7.x86_64

1.下载MySQL安装文件

下载主页https://dev.mysql.com/downloads/mysql/

根据前一步获取的系统版本选择进行下载,这里则是RH7 x86_64的版本进行下载

![image-20200609175530016](/Users/0x4154304d/Library/Application Support/typora-user-images/image-20200609175530016.png)

下载RPM Bundle版本

这里直接下载捆绑包,将所有的MySQL组件全部下载下来。然后解压文件包

tar -xvf xxxx.tar

2. 卸载系统附带的MySQL (不是每个用户都需要执行此步骤)

查看旧版本MySQL

rpm -qa | grep mysql

这里因为我已经成功安装新版本 所以系统会显示新版本

(base) ➜ ~ rpm -qa | grep mysql
mysql-community-common-8.0.20-1.el7.x86_64
mysql-community-libs-8.0.20-1.el7.x86_64
mysql-community-server-8.0.20-1.el7.x86_64
mysql-community-client-8.0.20-1.el7.x86_64

删除旧版本

rpm -e --nodeps xxxxxxxxx
#(xxxx就是上面查看出现的旧版本名字)
#eg:
# rpm -e --nodeps mysql-community-common-8.0.20-1.el7.x86_64

3.安装MySQL

根据依赖包的关系安装顺序分别为 common->libs->client->server

rpm -ivh mysql-community-common-8.0.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-libs-8.0.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-client-8.0.20-1.el7.x86_64.rpm
rpm -ivh mysql-community-server-8.0.20-1.el7.x86_64.rpm

4.登陆及修改密码

#启动MySQL
systemctl start mysqld.service
#查看MySQL当前状态
systemctl status mysqld.service
#关闭MySQL
systemctl stop mysqld.service

启动MySQL后查看默认密码

(base) ➜  ~ grep 'temporary password' /var/log/mysqld.log
2020-06-09T08:28:26.111487Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: 9>Z.iNW%WF?n

这里的9>Z.iNW%WF?n就是默认密码,之后登陆数据库

mysql -u root -p
#输入密码后成功登陆

修改密码

mysql> alter user root@localhost identified by 'xxxxxxxxxxxxxxxxx(新密码)';
#修改完成后重新登陆验证修改成功
\q