1、下载并安装MySQL官方的 Yum Repository
wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
2、安装mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
3、安装MySQL
yum -y install mysql-community-server
4、查看安装的MySQL信息
4.1、查看是否成功
[root@centos7 ~]# mysql -V
mysql Ver 14.14 Distrib 5.7.36, for Linux (x86_64) using EditLine wrapper
4.2、进入MySQL
安装完成后,系统会在 /var/log/mysqld.log 默认创建 root 密码,我们先获取到密码。
LnI!+M?fG8p6 这个便是 root的密码。
[root@centos7~]# grep "password" /var/log/mysqld.log
[Note] A temporary password is generated for root@localhost: LnI!+M?fG8p6
[Note] Access denied for user 'root'@'localhost' (using password: NO)
[Note] Access denied for user 'root'@'localhost' (using password: NO)
使用默认生成的密码登录MySQL后,不能进行,会提示如下的错误:
mysql> show databases;
ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.
mysql>
所以我们需要修改root的密码
ALTER USER 'root'@'localhost' IDENTIFIED BY 'new password';
修改完密码,退出重新登录后查看可以操作,到此 MySQL 数据库的安装完成
卸载 Yum Repository
yum -y remove mysql57-community-release-el7-10.noarch
备注内容:
使用yum -y install mysql-community-server安装mysql时候提示:
The GPG keys listed for the “MySQL 5.7 Community Server” repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.
Failing package is: mysql-community-libs-compat-5.7.37-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
原因是Mysql的GPG升级了,需要重新获取
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022