- 查看当前yum仓库是否包含mysql-server相关包
yum whatprovides mysql-server
- 下载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 whatprovides mysql-server
- 安装mysql
yum -y install mysql-server
如果报错: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.
原因:这是由于MySQL GPG 密钥已过期导致的问题,解决出处需要运行命令, 以2022年为例
解决:以2022年为例
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
- 启动
systemctl start mysqld
#设置开机启动
systemctl enable mysqld
systemctl daemon-reload
- 修改root密码
vim /var/log/mysqld.log
记住初始密码:
修改root 密码
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root123$%^';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'Root123$%^' WITH GRANT OPTION;
exit
-
配置mysql默认编码为utf-8
vim /etc/my.cnf
# 在文件末尾添加以下信息
character_set_server=utf8
init_connect='SET NAMES utf8'
-
重启MySQL
systemctl restart mysqld