当前位置: 首页 > news >正文

Centos7.9 安装mysql5.7

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

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

sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak

3.更换为国内镜像源

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 仓库包

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

sudo: wget:找不到命令

sudo yum install wget

5.安装 MySQL 5.7

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:

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

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

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

systemctl start mysqld
systemctl enable mysqld

7.获取临时密码并登录

查找 MySQL 的临时密码

sudo grep 'temporary password' /var/log/mysqld.log

使用临时密码登录 MySQL

mysql -u root -p

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

ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';

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

9.配置远程访问

USE mysql;
UPDATE user SET host='%' WHERE user='root';
FLUSH PRIVILEGES;

10.防火墙配置

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

firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload

11.修改 MySQL 端口(可选)

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

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

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

sudo systemctl restart mysqld

 12.使用Navicat连接

相关文章:

  • 【CV数据集】Visdrone2019无人机目标检测数据集(YOLO、VOC、COCO格式)
  • 今日行情明日机会——20250430
  • 11.多边形的三角剖分 (Triangulation) : 画廊问题
  • 深挖Java基础之:变量与类型
  • npm命令介绍(Node Package Manager)(Node包管理器)
  • 实验三 软件黑盒测试
  • 人工智能100问☞第14问:人工智能的三大流派(符号主义、联结主义、行为主义)有何区别?
  • C和指针笔记2——编译、链接
  • 攻防世界 dice_game
  • 模型开发之前的核心工作
  • 黄雀在后:外卖大战新变局,淘宝+饿了么开启电商大零售时代
  • Java大师成长计划之第9天:高级并发工具类
  • 存储器层次结构:理解计算机记忆的金字塔
  • 模型之FIM(Fill-In-the-Middle)补全
  • 12.多边形的三角剖分 (Triangulation) : Fisk‘s proof
  • 销售预测业务优化设计方案汇报P99(99页PPT)(文末有下载方式)
  • 总结C++中的STL
  • C++笔记-继承(下)(包含派生类的默认成员函数,菱形继承等)
  • 代码随想录单调栈part1
  • 使用CubeMX新建DMA工程——存储器到存储器模式
  • CMG亚太总站:没有邀请韩国偶像团体举办巡回演出
  • “非思”的思想——探索失语者的思想史
  • 国际油价重挫!美股道指连跌三月,啥情况?
  • 剑指3000亿产业规模,机器人“武林大会”背后的无锡“野望”
  • 160名老人报旅行团被扔服务区?张家界官方通报
  • 建发股份:将于5月6日召开股东大会,审议提名林茂等为公司新一届董事等议案