Centos7.9 安装mysql5.7

[复制链接]
发表于 2025-5-3 03:36:37 | 显示全部楼层 |阅读模式
1.配置镜像(7.9的镜像过期了)


2.备份原有的 CentOS 底子源配置文件

  1. sudo cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.bak
复制代码
3.更换为国内镜像源

  1. 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 堆栈包

  1. sudo wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
复制代码
sudo: wget:找不到命令
  1. sudo yum install wget
复制代码
5.安装 MySQL 5.7

  1. 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:
  1. rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
复制代码
安装gpg-key后再次安装mysql5.7,直到安装完成
6.启动 MySQL 服务并设置开机自启

  1. systemctl start mysqld
  2. systemctl enable mysqld
复制代码
7.获取临时密码并登录

查找 MySQL 的临时密码
  1. sudo grep 'temporary password' /var/log/mysqld.log
复制代码
利用临时密码登录 MySQL
  1. mysql -u root -p
复制代码
8.修改密码并举行安全配置

  1. ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';
复制代码
密码规则:大写+小写+数字+特殊符号
9.配置远程访问

  1. USE mysql;
  2. UPDATE user SET host='%' WHERE user='root';
  3. FLUSH PRIVILEGES;
复制代码
10.防火墙配置

如果启用了防火墙,需要放行 MySQL 端口(默以为 3306)
  1. firewall-cmd --zone=public --add-port=3306/tcp --permanent
  2. firewall-cmd --reload
复制代码
11.修改 MySQL 端口(可选)

编辑 MySQL 配置文件 /etc/my.cnf,修改 port 参数:
  1. vi /etc/my.cnf
复制代码


  • 将 port=3306 修改为其他端口,比方 port=3307。
  • 重启 MySQL 服务以应用更改:

  1. sudo systemctl restart mysqld
复制代码
 12.利用Navicat连接



免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
继续阅读请点击广告

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

© 2001-2025 Discuz! Team. Powered by Discuz! X3.5

GMT+8, 2025-7-9 04:46 , Processed in 0.085556 second(s), 31 queries 手机版|qidao123.com技术社区-IT企服评测▪应用市场 ( 浙ICP备20004199 )|网站地图

快速回复 返回顶部 返回列表