1. 下载并安装 MySQL 官方的 Yum Repository
wget https://repo.mysql.com//mysql80-community-release-el7-1.noarch.rpm
2、repo的安装
就是安装yum源
rpm -ivh mysql80-community-release-el7-1.noarch.rpm
执行完成后会在/etc/yum.repos.d/目录下生成两个repo文件mysql-community.repo mysql-community-source.repo
3.执行yum安装命令
yum install mysql-server
安装过程中 如果出现 “mysql-community-server-8.0.34-1.el7.x86_64.rpm 的公钥尚未安装”
解决办法参考链接 https://dev.mysql.com/doc/refman/8.0/en/checking-rpm-signature.html
也可直接通过url导入密钥
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
解决完后重新执行安装命令
启动mysql
systemctl start mysqld.service
查看MySQL运行状态
systemctl status mysqld.service
获取密码
grep “password” /var/log/mysqld.log
修改密码
获取密码后,登入修改密码,不修改密码无法进行数据库操作
mysql -uroot -p
//键入mysql密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';