CentOS7 yum 安装 mysql5.7

  • Post author:
  • Post category:mysql


  • 下载mysql的yum仓库文件包

wget http://repo.mysql.com/yum/mysql-5.7-community/el/7/x86_64/mysql57-community-release-el7-10.noarch.rpm

rpm -ivh mysql57-community-release-el7-10.noarch.rpm

  • 开始使用yum安装mysql

yum -y install mysql-server

注意:在安装mysql-server可能会出现以下报错:

Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
 Userid     : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
 Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
 Package    : mysql57-community-release-el7-10.noarch (installed)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql


Public key for mysql-community-libs-compat-5.7.38-1.el7.x86_64.rpm is not installed


 Failing package is: mysql-community-libs-compat-5.7.38-1.el7.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

这个报错是指mysql密钥过期了,需要更新一下密钥,更新完密钥之后,重新安装mysql-server即可。

rpm –import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

yum -y install mysql-community-server

  • 启动mysql

systemctl enable mysqld

systemctl start mysqld

systemctl status mysqld

  • 首次安装后,可以通过mysql日志查询默认密码,登录后修改密码即可。

cat /var/log/mysqld.log | grep password

初始密码登录后必须先执行修改密码才能进行其他操作

mysql -u root -p

ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘newpassword’;

FLUSH PRIVILEGES;

quit

  • 重启mysql服务

systemctl restart mysqld

至此通过yum 安装 mysql完成。