yum --version
#查看下载工具版本
yum search mysql
#搜索软件
如报错:1.网络不可达,检测网络是否通畅
- 替换镜像源
替换镜像源:
备份原有yum源配置文件:
# 创建备份目录 mkdir -p /etc/yum.repos.d/bak # 移动原有 repo 文件到备份目录 mv /etc/yum.repos.d/*.repo /etc/yum.repos.d/bak/
# 下载阿里云 CentOS 7 基础源wget-O/etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
# 清理旧缓存yum clean all# 重建新缓存yum makecache
# 下载 MySQL 官方 yum 源配置包(适配 CentOS 7)wgethttps://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm
# 安装配置包(会在 /etc/yum.repos.d/ 生成 MySQL 源配置文件)rpm-ivhmysql80-community-release-el7-3.noarch.rpm
# 列出所有可安装的 mysql-community-server 包(包含完整版本号)yum list--showduplicatesmysql-community-server
#下载对应版本的软件
yuminstall-ymysql-community-server-8.0.44-1.el7.x86_64
首先下载对应版本所需密钥
# 方式 1:用 wget 下载(推荐)wget-O/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022 https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
# 查看文件是否存在ls-l/etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
# 1. 导入刚下载的 2022 版密钥 rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022 # 2. 修改 MySQL yum 源配置,指定使用新密钥 sed -i 's|gpgkey=.*|gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022|' /etc/yum.repos.d/mysql-community.repo # 3. 清理 yum 缓存(避免旧配置干扰) yum clean all yum makecache
重新安装即可。
如安装失败,直接跳过GPG验证:
yuminstall-y--nogpgcheckmysql-community-server-8.0.44-1.el7.x86_64
安装完成。。。。。
#启动mysql服务
Systemctl start mysqld
#开机自启
Systemctl enable mysqld
#查看版本
Mysql --version
查看运行状态
Systemctl status mysqld
# mysql安装后产生临时密码,查看临时密码
2026-01-15T04:29:17.246681Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost:_X?OtIQ;+7ug
#更改临时密码
ALTERUSER'root'@'localhost'IDENTIFIEDBY'04551Jhh@';
原本登陆需进行,mysql服务启动,输入密码我觉得太麻烦
创建脚本文件:
Vim mysql_LOGIN.sh
#!/bin/bash
#检查mysql服务是否运行,没运行就进行自启动
systemctl is-active --quiet mysqld || systemctl start mysqld
#一键登陆root账户
mysql -uroot -p'04551Jhh@'
写入脚本完成后,运行脚本即可完成登陆。
配置MySQL配置文件:
#创建MySQL配置文件
Vim ~/.my.cnf
~:代表隐藏文件
[client]
user=root
password=04551Jhh@
lost=localhost
给上述配置文件添加权限
Chmod 600 ~/.my.conf(mysql权限校验如大于600会默认存在安全隐患)
权限添加完成后输入mysql即可进去mysql
下载DBeaver方便对数据库进行数据等可视化