首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫

CentOS 7 透過官方 Yum 源安裝 MySQL Server 完整步驟

     編輯:MySQL 資料庫相關知識

CentOS 7 系統盤不再預設提供 mysql-server RPM 包,需透過 MySQL 官方 Yum Repository 進行安裝。本文記錄配置 Repo、解決 GPG Key 錯誤並成功安裝 MySQL 5.6/5.7 的實戰過程。

一、建立 MySQL 官方 Yum Repository

在 /etc/yum.repos.d/ 建立 mysql-community.repo:

MySQL 5.6 版本配置:

# Enable to use MySQL 5.6
[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=https://repo.mysql.com/yum/mysql-5.6-community/el/5/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

MySQL 5.7 版本配置:

# Note: MySQL 5.7 is currently in development. For use at your own risk.
# Please read with sub pages: https://dev.mysql.com/doc/relnotes/mysql/5.7/en/
[mysql57-community-dmr]
name=MySQL 5.7 Community Server Development Milestone Release
baseurl=https://repo.mysql.com/yum/mysql-5.7-community/el/6/$basearch/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql

二、安裝 MySQL Community Server

yum install mysql-community-server

三、解決 GPG Key 驗證失敗

若遇到錯誤:GPG key retrieval failed: [Errno 14] curl#37 - "Couldn't open file /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql"

原因是本地缺少 GPG Key 檔案,修改 Repo 設定關閉 GPG 檢查:

[mysql56-community]
name=MySQL 5.6 Community Server
baseurl=https://repo.mysql.com/yum/mysql-5.6-community/el/5/$basearch/
enabled=1
gpgcheck=0

重新執行安裝即可成功:

yum install mysql-community-server

四、後續設定建議

  • 啟動服務:systemctl start mysqld
  • 設定開機自啟:systemctl enable mysqld
  • 執行安全初始化:mysql_secure_installation
  • 開放防火牆 3306 埠:firewall-cmd --permanent --add-port=3306/tcp
  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved