1、检查一下自己电脑上安装了哪些mysql
[root@localhost ~]# find / -name mysql
2、把安装的mysql全部删掉
[root@localhost ~]# rm -rf /usr/lib64/mysql/
[root@localhost ~]# rm -rf /usr/local/mysql/
[root@localhost ~]# rm -rf /etc/selinux/targeted/active/modules/100/mysql/
3、查看自己的包卸载完成没有
[root@localhost ~]# find / -name mysql
find: ‘/run/user/1000/gvfs’: Permission denied
4、下载安装包
[root@localhost ~]# wget https://downloads.mysql.com/archives/community/mysql-community-server-8.0.31-1.el7.x86_64.rpm
5、如果需要下载最新包请去官网下载,下载地址:MySQL :: Download MySQL Community Server (Archived Versions) (已经下载好了的,可以省略这一步)
6、再下载一个community的包
[root@localhost ~]# wget https://downloads.mysql.com/archives/community/
7、再执行下面的两个命令即可
[root@localhost /]# cd /usr/local/
[root@localhost local]# wget https://dev.mysql.com/get/mysql80-community-release-el8-4.noarch.rpm
8、安装community-server
[root@localhost local]# yum -y install mysql-community-server
9、然后执行一下下面的两个命令
[root@localhost local]# systemctl start mysqld
[root@localhost local]# systemctl status mysqld
设置开机自启服务(需要的可以自行设置):
[root@localhost ~]# systemctl enable mysqld
10、查看一下初始密码是多少
[root@localhost local]# cat /var/log/mysqld.log | grep password
11、输入账号和密码
[root@localhost local]# mysql -u root -p
Enter password:
12、修改初始密码
mysql> alter user 'root'@'localhost' identified by '您的密码';
希望对你有所帮助,谢谢~