1.1 下载mysql 8.0

https://downloads.mysql.com/archives/community/

1.2 解压压缩包

tar xvf mysql-8.0.36-1.el7.x86_64.rpm-bundle.tar

1.3 安装命令

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

1.3.1 报错 mariadb-libs

[root@iZ2zeidwqat5m14e8uc0urZ mysql]# rpm -ivh mysql-community-libs-8.0.36-1.el7.x86_64.rpm

warning: mysql-community-libs-8.0.36-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID a8d3785c: NOKEY

error: Failed dependencies:

        mariadb-libs is obsoleted by mysql-community-libs-8.0.36-1.el7.x86_64

解决方案:卸载mysql-libs

yum remove mysql-libs

1.3.2 报错 libnuma.so.1

yum -y install numactl

1.3.3 报错 libaio.so.1()(64bit) is needed by MySQL-server

yum install libaio

1.3.4 报错 pkgconfig(openssl) 被 mysql-community-devel-8.0.26-1.el7.x86_64 需要

yum install openssl-devel

1.4 启动Mysql

1.4.1 初始化mysql服务

mysqld --initialize --user=mysql

执行完初始化命令后,会为root用户生成一个临时密码并保存在日志中,可以使用如下命令查看密码,后面登录需要使用该密码

cat /var/log/mysqld.log

-- 查询结果:qZKEb#tJu2yp

1.4.2 启动服务

systemctl start mysqld

1.4.3 连接服务

  mysql -uroot -p

  qZKEb#tJu2yp

1.4.4 初次登录修改密码

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

1.4.5 修改root可外网登录

  use mysql;

  update user set host='%' where user='root';

  flush privileges;