Centos7.9 安装mysql5.7

1.配置镜像(7.9的镜像过期了)

2.备份原有的 CentOS 基础源配置文件

bash 复制代码
sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

3.更换为国内镜像源

bash 复制代码
sudo vi /etc/yum.repos.d/CentOS-Base.repo

将文件内容替换为以下内容:

CentOS-Base.repo # # The mirror system uses the connecting IP address of the client and the # update status of each mirror to pick mirrors that are updated to and # geographically close to the client. You should use this for CentOS updates # unless you are manually picking other mirrors. # # If the mirrorlist= does not work for you, as a fall back you can try the # remarked out baseurl= line instead. # # [base] name=CentOS-releasever - Base - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/releasever/os/basearch/ http://mirrors.aliyuncs.com/centos/releasever/os/basearch/ http://mirrors.cloud.aliyuncs.com/centos/releasever/os/basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #released updates \[updates\] name=CentOS-releasever - Updates - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that may be useful [extras] name=CentOS-releasever - Extras - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/releasever/extras/basearch/ http://mirrors.aliyuncs.com/centos/releasever/extras/basearch/ http://mirrors.cloud.aliyuncs.com/centos/releasever/extras/basearch/ gpgcheck=1 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7 #additional packages that extend functionality of existing packages \[centosplus\] name=CentOS-releasever - Plus - mirrors.aliyun.com failovermethod=priority baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/ http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/ http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/ gpgcheck=1 enabled=0 gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7

Esc 键,输入 :wq 保存并退出。

4.下载并安装 MySQL 的 YUM 仓库包

bash 复制代码
sudo wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm

sudo: wget:找不到命令

bash 复制代码
sudo yum install wget

5.安装 MySQL 5.7

bash 复制代码
yum install -y mysql-community-server

安装过程中止报错:Failing package is: mysql-community-server-5.7.44-1.el7.x86_64

GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql,如下图:

需要安装gpg-key:

bash 复制代码
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022 

安装gpg-key后再次安装mysql5.7,直到安装完成

6.启动 MySQL 服务并设置开机自启

bash 复制代码
systemctl start mysqld
systemctl enable mysqld

7.获取临时密码并登录

查找 MySQL 的临时密码

bash 复制代码
sudo grep 'temporary password' /var/log/mysqld.log

使用临时密码登录 MySQL

bash 复制代码
mysql -u root -p

8.修改密码并进行安全配置

bash 复制代码
ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';

密码规则:大写+小写+数字+特殊符号

9.配置远程访问

bash 复制代码
USE mysql;
UPDATE user SET host='%' WHERE user='root';
FLUSH PRIVILEGES;

10.防火墙配置

如果启用了防火墙,需要放行 MySQL 端口(默认为 3306)

bash 复制代码
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

11.修改 MySQL 端口(可选)

编辑 MySQL 配置文件 /etc/my.cnf,修改 port 参数:

bash 复制代码
vi /etc/my.cnf
  • port=3306 修改为其他端口,例如 port=3307

  • 重启 MySQL 服务以应用更改:

bash 复制代码
sudo systemctl restart mysqld

12.使用Navicat连接

相关推荐
shejizuopin1 小时前
基于JavaSSM+MySQL的实验室考勤管理系统设计与实现
java·mysql·vue·毕业设计·论文·springboot·实验室考勤管理系统设计与实现
oMcLin1 小时前
如何在 CentOS 8 上部署并优化 Jenkins 2.x 流水线,提升 CI/CD 流程的自动化与高效性
ci/cd·centos·jenkins
alonewolf_991 小时前
MySQL全局优化详解与8.0新特性全面解读
数据库·mysql
oMcLin1 小时前
如何在 CentOS 7.9 上配置并调优 Docker Swarm 集群,确保跨多个节点的高效服务发现与负载均衡?
docker·centos·服务发现
不染尘.1 小时前
Linux基本概述
linux·windows·centos·ssh
Full Stack Developme2 小时前
Mycat 2 实现 MySQL 读写分离,并且实现 主从同步
android·数据库·mysql
alonewolf_992 小时前
MySQL Explain详解与索引优化实战
数据库·mysql·adb
それども2 小时前
MySQL 查询索引最左前缀原则,如果是(a,b)的联合索引,WHERE b = ? AND a = ?会走索引吗
数据库·mysql
それども2 小时前
MySQL EXPLAIN Impossible WHERE noticed after reading const tables
数据库·mysql
萧曵 丶14 小时前
MySQL 主键不推荐使用 UUID 的深层原因
数据库·mysql·索引