1、如果服务器没有wget,先下载wget工具
sudo yum install wget
2、下载指定mysql版本的tar包
sudo wget https://downloads.mysql.com/archives/get/p/23/file/mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar
3、解压tar包
sudo tar -xvf mysql-8.0.21-1.el7.x86_64.rpm-bundle.tar
4、卸载mariadb
# 查看安装包
rpm -qa | grep mariadb
# 卸载
rpm -e mariadb-libs-5.5.68-1.el7.x86_64 --nodeps
5、安装相关配置的rpm包
sudo rpm -ivh mysql-community-common-8.0.21-1.el7.x86_64.rpm --nodeps --force
sudo rpm -ivh mysql-community-libs-8.0.21-1.el7.x86_64.rpm --nodeps --force
sudo rpm -ivh mysql-community-client-8.0.21-1.el7.x86_64.rpm --nodeps --force
sudo rpm -ivh mysql-community-server-8.0.21-1.el7.x86_64.rpm --nodeps --force
6、对mysql数据库进行初始化和相关配置
mysqld --initialize
chown mysql:mysql /var/lib/mysql -R
systemctl start mysqld.service
systemctl enable mysqld
# 查看初始密码
cat /var/log/mysqld.log | grep password
# 使用初始密码进入到mysql更新密码
mysql -uroot -p
alter user 'root'@'localhost' identified with mysql_native_password by '123456';
exit
# 使用新密码重新登录
mysql -uroot -p
7、配置进行远程访问的授权
create user 'root'@'%' identified with mysql_native_password by '123456';
grant all privileges on *.* to 'root'@'%' with grant option;
flush privileges;
8、使用navicat测试连接
如果服务器上有残留的mysql,可使用如下步骤进行卸载
# 查看已安装的mysql安装包
rpm -qa | grep mysql
# 使用如下命令将搜索到的mysql安装包全部卸载
rpm -e --nodeps mysql-community-server-8.0.21-1.el7.x86_64
# 删除配置文件
rm -rf /etc/my.cnf.rpmsave
# 删除日志文件
rm -rf /var/log/mysqld.log
# 查看并删除其他残留文件
find / -name mysql
# 依次删除
rm -rf 对应路径